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

相关内容

热门资讯

重磅来袭(aapoker实测)... 重磅来袭(aapoker实测)外挂透明挂辅助挂(透视)德州ai机器人(竟然有挂)-哔哩哔哩;原来确实...
玩家必看教程(德州poker)... 1、玩家必看教程(德州poker)外挂透明挂辅助app(辅助挂)专业教程(2024已更新)(哔哩哔哩...
每日必看推荐(pokerwoe... 每日必看推荐(pokerwoeld安卓下载)外挂透明挂辅助器(辅助挂)软件透明挂(有挂技巧)-哔哩哔...
一分钟了解(微扑克专用)外挂透... 一分钟了解(微扑克专用)外挂透明挂辅助挂(透视)软件透明挂(有挂分享)-哔哩哔哩;玩家必备必赢加哟《...
1分钟了解(德扑之星软件)外挂... 1、1分钟了解(德扑之星软件)外挂透明挂辅助app(辅助挂)新2024版(2020已更新)(哔哩哔哩...
透明科技!WPK(wEpoKe... 透明科技!WPK(wEpoKe)外挂透明挂辅助插件(辅助挂)详细教程(讲解有挂)-哔哩哔哩;揭秘教程...
分享个大家(aapoker安卓... 1、分享个大家(aapoker安卓版)外挂透明挂辅助脚本(透视)软件透明挂(新版有挂)-哔哩哔哩;详...
程序员教你(轰趴大菠萝十三水)... 程序员教你(轰趴大菠萝十三水)外挂透明挂辅助插件(辅助挂)软件透明挂(有挂方略)-哔哩哔哩;免费轰趴...
透视辅助(Wepoke必胜)外... 透视辅助(Wepoke必胜)外挂透明挂辅助app(透视)新2024教程(2021已更新)(哔哩哔哩)...
科普攻略(线上wpk德州)外挂... 科普攻略(线上wpk德州)外挂透明挂辅助app(辅助挂)透视辅助(有挂细节)-哔哩哔哩;亲们利用一分...