简体   繁体   English

Apache Camel发送消息JMS Consumer接收消息

[英]Apache Camel send message JMS Consumer receives message

Have Apache Camel simple message route from folder to ActiveMQ topic: 使Apache Camel从文件夹到ActiveMQ主题的简单消息路由:

//Create context to create endpoint, routes, processor within context scope
        CamelContext context = new DefaultCamelContext();


        //Create endpoint route
        context.addRoutes(new RouteBuilder() {

            @Override
            public void configure() throws Exception 
            {
                from("file:data/outbox").to("activemq:topic:Vadim_Topic");
                //from("activemq:topic:TEST").to.to("file:data/outbox");
            }

        });

        context.start();
            Thread.sleep(5000);
        context.stop();
    }

And JMS implementation if Topic Consumer: 和JMS实现,如果Topic Consumer:

ConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
        try {

            Connection connection = connectionFactory.createConnection();
            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

            //connection.setClientID("12345");

            connection.start();
            Topic topic = session.createTopic("Vadim_Topic");
            MessageConsumer messageConsumer = session.createConsumer(topic);

            MessageListener messageListener = new MessageListener() {

                public void onMessage(Message message) {

                    TextMessage textMessage = (TextMessage) message;
                    try {
                        System.out.println("Received message: " + textMessage.getText());
                    } catch (JMSException e) {
                        e.printStackTrace();
                    }
                }
            };

            messageConsumer.setMessageListener(messageListener);

        } catch (Exception e) {
            e.printStackTrace();
        }

Can't understand why is my consumer can't recieve messages sent by Camel route?? 无法理解为什么我的消费者无法收到骆驼路线发送的消息? I guess thet problem is then I need to subscribe my JMS Consumer on messages sent by Camel? 我想这是我需要在Camel发送的消息上订阅我的JMS Consumer吗? How can I do this if this is the case? 如果是这种情况,我该怎么办?

Camel not only allows you to send messages to a topic, it can also very easily read messages from a topic and send it to one of your POJOs. Camel不仅允许您将消息发送到主题,还可以非常轻松地从主题中读取消息并将其发送到您的POJO之一。

A route that reads from your topic and sends the messages to a POJO would look like this: 从您的主题读取并将消息发送到POJO的路由如下所示:

from("activemq:topic:Vadim_Topic").bean(ExampleBean.class);

Camel will figure out which method to call on the POJO depending on the type of message it received, and the available method signatures. Camel会根据收到的消息类型以及可用的方法签名来确定在POJO上调用哪种方法。 See this page for details on using POJO's in camel routes: https://camel.apache.org/bean.html 有关在骆驼路线中使用POJO的详细信息,请参见此页面: https : //camel.apache.org/bean.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM