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

相关内容

热门资讯

透视好友!hhpoker德州牛... 透视好友!hhpoker德州牛仔视频,hhpoker有透视功能吗(透视)原先真的有挂(wepoke教...
透视脚本!fishpoker透... 透视脚本!fishpoker透视,德州局透视脚本,其实是有挂(扑克教程)一、德州局透视脚本软件透明挂...
透视数据!wepoker透视功... 透视数据!wepoker透视功能下载,we-poker正规吗(透视)一贯有挂(线上教程);1、打开软...
透视智能ai!fishpoke... 透视智能ai!fishpoker透视底牌,哈糖大菠萝万能挂,确实真的是有挂(攻略教程);1、下载好哈...
透视透视挂!悦扑克脚本,拱趴大... 透视透视挂!悦扑克脚本,拱趴大菠萝作弊方法(透视)固有真的是有挂(揭秘攻略)1、进入游戏-大厅左侧-...
透视规律!智星德州插件2024... 透视规律!智星德州插件2024最新版,德州真人透视脚本,都是真的有挂(AI教程)1、智星德州插件20...
透视线上!wpk俱乐部有没有辅... 透视线上!wpk俱乐部有没有辅助,aapoker怎么拿好牌(透视)都是有挂(透牌教程)wpk俱乐部有...
透视最新!newpoker脚本... 透视最新!newpoker脚本,pokemmo脚本,切实是有挂(揭秘教程);进入游戏-大厅左侧-新手...
透视挂!xpoker透视辅助,... 透视挂!xpoker透视辅助,德普软件(透视)真是有挂(玩家教程);1、用户打开应用后不用登录就可以...
透视科技!德州私人局怎么透视,... 透视科技!德州私人局怎么透视,pokermaster修改器,一贯真的有挂(2025新版技巧);1、下...