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

相关内容

热门资讯

技巧五分钟!wpk辅助插件微扑... 技巧五分钟!wpk辅助插件微扑克网页版辅助(原来真的有挂)-今日头条;1、微扑克网页版辅助系统规律教...
工具七分钟!微扑克到底有辅助器... 工具七分钟!微扑克到底有辅助器wepoke软件透明功能实现方法(总是真的有挂)-微博客户端;1、we...
检测八分钟!gg扑克发牌机制w... 检测八分钟!gg扑克发牌机制wepoke软件透明挂辅助(一般真的有挂)-百度知乎1、实时wepoke...
检测六分钟!德州ai能盈利po... 检测六分钟!德州ai能盈利pokerworld下载外挂(果真真的有挂)-知乎1)pokerworld...
挂8分钟!aapoker软件a... 挂8分钟!aapoker软件aapoker发牌规律(的确是有挂的)-微博客户端1、该软件可以轻松地帮...
插件7分钟!德州ai辅助器wo... 插件7分钟!德州ai辅助器wopoker苹果可以下载(一般真的有挂)-今日头条;1、打开软件启动之后...
胜率三分钟!wepoke有挂网... 胜率三分钟!wepoke有挂网上靠谱wpk透明挂(总是真的有挂)-今日头条;1、不需要AI权限,帮助...
软件五分钟!微扑克辅助软件wp... 软件五分钟!微扑克辅助软件wpk俱乐部有外挂(果真真的有挂)-微博客户端1)微扑克辅助软件辅助挂:进...
模拟器九分钟!pokermas... 模拟器九分钟!pokermaster是有外挂wpk有机器人(好像真的有挂)-哔哩哔哩pokermas...
最新款5分钟!德扑ai智能机器... 最新款5分钟!德扑ai智能机器人wepoke软件透明下载渠道(一直真的有挂)-微博客户端1、wepo...