如何为python发件人创建一个spring boot rabbitmq使用者?

时间:2018-03-27 12:31:18

标签: java spring-boot rabbitmq spring-rabbitmq

我想开发一个应用程序,其中python代码使用rabbitmq发送消息,而消费者是Spring boot rabbitmq代码。

sender.py

#!/usr/bin/env python
import pika
import sys

connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()

channel.exchange_declare(exchange='topic_logs',
                     exchange_type='topic')

routing_key = sys.argv[1] if len(sys.argv) > 2 else 'anonymous.info'
message = ' '.join(sys.argv[2:]) or 'Hello World!'
channel.basic_publish(exchange='topic_logs',
                  routing_key=routing_key,
                  body=message)
print(" [x] Sent %r:%r" % (routing_key, message))
connection.close()

如何使用弹簧启动配置rabbitmq接收器?接收方需要哪些必要的配置?请帮忙。

1 个答案:

答案 0 :(得分:1)

02F05DFC               bl         _ZNKSt6__ndk16__treeINS_12__value_typeINS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEES7_EENS_19__map_value_compareIS7_S8_NS_4lessIS7_EELb1EEENS5_IS8_EEE4findIS7_EENS_21__tree_const_iteratorIS8_PNS_11__tree_nodeIS8_PvEEiEERKT_
3096                   str        r6, [sp, #0x108 + var_48]
0146                   mov        r1, r0
CDE92E66               strd       r6, r6, [sp, #0x108 + var_50]
11F81C2F               ldrb       r2, [r1, #0x1c]!
12F0010F               tst.w      r2, #0x1
06D1                   bne        loc_THERE

                  loc_FIRST:
D1E90002               ldrd       r0, r2, [r1]
8968                   ldr        r1, [r1, #0x8]
3091                   str        r1, [sp, #0x108 + var_48]
CDE92E02               strd       r0, r2, [sp, #0x108 + var_50]
04E0                   b          loc_HERE

                  loc_THERE:
D0E90821               ldrd       r2, r1, [r0, #0x20]
2EA8                   add        r0, sp, #0xb8_ZNSt6__ndk112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initEPKcj
FDF743FD               bl         _ZNSt6__ndk112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initEPKcj

                  loc_HERE:
2EA9                   add        r1, sp, #0xb8
2046                   mov        r0, r4
04F047FB               bl         _ZN6myobject11saveENSt6__ndk112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE

或者,如果交换已经存在......

@SpringBootApplication
public class So49512910Application {

    public static void main(String[] args) {
        SpringApplication.run(So49512910Application.class, args);
    }

    @Bean
    public Queue queue() {
        return new Queue("someQueue");
    }

    @Bean
    public TopicExchange exchange() {
        return new TopicExchange("topic_logs");
    }

    @Bean
    public Binding binding() {
        return BindingBuilder.bind(queue()).to(exchange()).with("whatever.topic.pattern.you.want.to.match");
    }

    @RabbitListener(queues = "someQueue")
    public void listener(String in) {
        System.out.println(in);
    }

}