ApacheCamel中非JavaActiveMQ消费者引起的桥接错误
创始人
2024-09-05 14:30:49
0

在 Apache Camel 中,当使用 ActiveMQ 的非 Java 消费者时,在桥接期间可能会引起以下错误:

java.lang.UnsupportedOperationException: Not supported for non-Java consumers: destinationType=TOPIC

这是因为 ActiveMQ 支持多种不同的消费者,但只有 Java 消费者可以使用 Apache Camel 桥接。如果您想在 Camel 中使用非 Java 消费者,则需要创建自定义代码来桥接消息。

以下是一些示例代码来处理这个问题。首先,您需要创建一个 ActiveMQ 组件并自定义消息桥接代码:

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQDestination;

public class MyBridgeComponent extends ActiveMQComponent {
  
  private String uri; // the ActiveMQ broker URI
  
  public MyBridgeComponent(String uri) {
    super(new ActiveMQConnectionFactory(uri));
    this.uri = uri;
  }
  
  public void bridgeMessage(ActiveMQDestination from, ActiveMQDestination to, Message message) {
    // create a new connection to ActiveMQ
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(uri);
    Connection connection = factory.createConnection();
    connection.start();
    
    // create a session and producer for the target destination
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = session.createProducer(to);
    
    // create a consumer for the source destination
    // if this is a topic, also create a durable subscriber
    DurableSubscriptionId subId = null;
    MessageConsumer consumer;
    if (from.isTopic()) {
      subId = new DurableSubscriptionId("MyBridgeComponent", from.getPhysicalName(), message.getJMSMessageID());
      consumer = session.createDurableSubscriber((Topic) from, subId.toString());
    } else {
      consumer = session.createConsumer(from);
    }
    
    // get the message and copy its contents to a new message
    Message receivedMessage = consumer.receive();
    TextMessage newMessage = session.createTextMessage(receivedMessage.getBody(String.class));
    
    // copy message properties and headers
    Enumeration property

相关内容

热门资讯

每日必看!老友跑得快辅助小说最... 每日必看!老友跑得快辅助小说最新章节,wepoker模拟器哪个好用,详细教程(讲解有挂);详细老友跑...
关于!摸一把游戏辅助软件,德州... 您好:摸一把游戏辅助软件这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户的...
盘点十款!皮皮游戏辅助平台,w... 您好,皮皮游戏辅助平台这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多玩家在...
揭秘!皮皮手游辅助,德普之星怎... 揭秘!皮皮手游辅助,德普之星怎么设置埋牌,透明教程(有挂讲解);揭秘!皮皮手游辅助,德普之星怎么设置...
必备教程!佛手大菠萝破解版io... 必备教程!佛手大菠萝破解版ios,wepoker辅助软件价格,玩家教你(有挂细节);1、让任何用户在...
重磅来袭!欢乐卡五星插件,约局... 重磅来袭!欢乐卡五星插件,约局吧如何查看是否有挂,2025教程(有挂方法)是一款可以让一直输的玩家,...
实操分享!随意玩辅助器,epo... 实操分享!随意玩辅助器,epoker有透视吗,2025新版(有挂透明挂);随意玩辅助器是一种具有地方...
盘点一款!天道辅助器使用教程,... 盘点一款!天道辅助器使用教程,wepoker透视有吗,存在挂教程(真实有挂);相信小伙伴都知道这个天...
记者爆料!牵手跑得软件,wep... 记者爆料!牵手跑得软件,wepoker高级辅助,总结教程(有挂助手);牵手跑得软件免费下载原版,在牵...
最新研发!维系小程序雀神挂件,... 最新研发!维系小程序雀神挂件,wepoker软件辅助程序,解密教程(果真有挂)是一款可以让一直输的玩...