简体   繁体   English

骆驼路线以向主题发布消息并从队列中接收消息

[英]camel routes to publish message to the topic and recieve them from the queue

For some test client I am using yopa library that imitate local aws . 对于某些测试客户端,我正在使用模仿本地aws yopa库。 In order to publish message to the topic and then recieve it to the queue I do like this 为了将消息发布到主题,然后将其接收到队列中,我喜欢这样

    AmazonSQS amazonSQSClient = AmazonSQSClientBuilder.standard()
            .withCredentials(new AWSCredentialsProvider() {
                @Override
                public AWSCredentials getCredentials() { return null; }

                @Override
                public void refresh() { }
            })
            .withEndpointConfiguration(new EndpointConfiguration("http://localhost:47195", "yopa-local")) // local stub
            .build();
    AmazonSNS amazonSNSClient = AmazonSNSClientBuilder.standard()
            .withCredentials(new AWSCredentialsProvider() {
                @Override
                public AWSCredentials getCredentials() { return null; }

                @Override
                public void refresh() { }
            })
            .withEndpointConfiguration(new EndpointConfiguration("http://localhost:47196", "yopa-local")) // local stub
            .build();
    amazonSNSClient.publish("arn:aws:sns:yopa-local:000000000000:test-topic-with-subscriptions",
            "This is my message");
    ReceiveMessageResult message = 
            amazonSQSClient.receiveMessage("http://localhost:47195/queue/test-subscribed-queue-standard");
    System.out.println("Number of recievied messages: " + message.getMessages().get(0));

It works fine. 工作正常。

But how to implement that flow using apache camel and spring ? 但是如何使用apache camelspring实现这种流程呢?

When I create routes like this 当我创建这样的路线时

<routeContext id="myRoute" xmlns="http://camel.apache.org/schema/spring">
    <route id="publish.route">
        <from uri="bean:snsPublisher?method=publish({{sns.topic}}, ${body})"/>
        <to uri="arn:aws:sns:yopa-local:000000000000:test-topic-with-subscriptions"/>
        <onException redeliveryPolicyRef="redeliveryPolicy">
            <exception>java.lang.Exception</exception>
            <handled>
                <constant>{{camel.handle.exception}}</constant>
            </handled>
        </onException>
    </route>
</routeContext>

With publisher bean publisher bean

public class SnsPublisher extends SnsClient implements IPublisher<String> {
    @Override
    public void publish(String topic, String message) {
        try {
            PublishResult publishResult = getAmazonSNSClient().publish("arn:aws:sns:yopa-local:000000000000:test-topic-with-subscriptions", message);
        } catch (AmazonSNSException exception) {
        }
    }
}

( SnsClient is class that provides the same AmazonSNS object as in previous example.) SnsClient是提供与前面的示例相同的AmazonSNS对象的类。)

Even at start of the application I get 即使在应用程序启动时

Caused by: org.apache.camel.ResolveEndpointFailedException: 
Failed to resolve endpoint: arn://aws:sns:yopa-local:000000000000:test-topic-with-subscriptions due to: No component found with scheme: arn

org.apache.camel.RuntimeCamelException: org.apache.camel.FailedToCreateRouteException: 
Failed to create route publish.route at: >>> To[arn:aws:sns:yopa-local:000000000000:test-topic with-subscriptions] <<< in route: Route(publish.route [[From[bean:snsPublisher... because of Failed to resolve endpoint: arn://aws:sns:yopa-local:000000000000:test-topic-with-subscriptions due to: No component found with scheme: arn
No component found with scheme: arn

this says "arn" is not a component name that camel can recognise. 这说明“ arn”不是骆驼可以识别的组件名称。

Camel's url starts with name of one camel component, which should defined first. 骆驼的网址以一个骆驼组件的名称开头,应首先定义。

For example, if you connect to activemq, you should implement a JmsComponent or ActiveMQComponent, with a name,let's say, "amq", then you can connect to "amq:xxxx" in camel uri. 例如,如果连接到activemq,则应实现一个JmsComponent或ActiveMQComponent,其名称为“ amq”,然后可以连接到骆驼uri中的“ amq:xxxx”。

I never used aws, so I can't give your very specific advice. 我从未使用过aws,因此无法提供您非常具体的建议。 What I can tell you is that you need to implement a "arn" component, maybe it exists in some third-party library, or you need to write your own camel component class. 我可以告诉您的是,您需要实现一个“ arn”组件,它可能存在于某些第三方库中,或者您需要编写自己的骆驼组件类。

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

相关问题 骆驼从队列中消费消息但无法重新创建它 - Camel consuming message from queue but fails to recreate it Apache Camel — Hazelcast主题发布/订阅—如何在订户中序列化String消息 - Apache Camel — Hazelcast Topic Publish/Subscribe — how to serialize String message in Subscriber 从数据库中读取并同时将消息发布到主题 - Read from the Database and Publish the message to a topic at the same time RabbitMQ + Spring集成:从队列绑定到主题交换的消息转换 - RabbitMQ + Spring Integration: Message conversion from queue bound to a topic exchange Apache骆驼:过滤器/限制器仅从队列中提取第一条消息 - Apache camel: filter / throttle to take just the first message from a queue Apache Camel:从消息正文中提取队列名称 - Apache Camel : extract to-queue name from message body 按照Camel和JMS的高级队列以正确的顺序使用消息 - Consuming message in the correct order from an Advanced Queue by Camel and JMS ActiveMQ Topic to Queue,当从Master切换到Slave时使用Camel路由消息丢失? - ActiveMQ Topic to Queue, When using Camel route messages getting lost when switching from Master to Slave? 是否可以将消息从XA队列提交到Camel中的非XA队列? - Is it possible to commit the message from XA queue to non-XA queue in Camel? 如何在Lagom中向Kafka主题发布消息 - How to publish a message to a Kafka Topic in Lagom
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM