简体   繁体   English

如何为python发送者创建spring boot rabbitmq使用者?

[英]How to create a spring boot rabbitmq consumer for a python sender?

I want develop an application where in the python code sends the message using rabbitmq and the consumer is Spring boot rabbitmq code. 我想开发一个应用程序,其中在python代码中使用rabbitmq发送消息,而使用者是Spring boot rabbitmq代码。

sender.py 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()

How do I configure a rabbitmq receiver using spring boot? 如何使用Spring Boot配置Rabbitmq接收器? What are the necessary configurations required at the receiver side? 接收方需要哪些必要的配置? Please help. 请帮忙。

@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);
    }

}

Or, if the exchange already exists... 或者,如果交换已经存在...

@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 Binding binding() {
        return new Binding("someQueue", DestinationType.QUEUE, "topic_logs", "rk.pattern", null);
    }

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

}

暂无
暂无

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

相关问题 如何为python接收器编写spring boot rabbitmq发送器? - How do I write a spring boot rabbitmq sender for a python receiver? 如何在Spring Boot Rabbitmq中分别配置生产者和消费者? - How to separately configure producer and consumer in spring boot rabbitmq? 如何在Spring Boot API中实现RabbitMQ消费者部分(receiver) - How to Implement RabbitMQ consumer part(receiver ) inside the Spring boot API 如何在Spring Boot中设置amqp RabbitMQ消费者标签? - How to set amqp RabbitMQ consumer tag in Spring Boot? 使用 rabbitmq 时如何分别配置消费者和生产者 spring 启动应用程序? - How to configure separately both consumer and producer spring boot app when using rabbitmq? 如何在 Spring Boot 中创建一个 rabbitmq 队列但不使用 @Bean - How to create a rabbitmq Queue in Spring Boot but without using @Bean 如何创建单独的 JMS 消费者和发布者 spring 引导应用程序? - How to create separate JMS consumer and publisher spring boot application? 我可以在 rabbitMQ 和 spring 引导中将多个队列绑定到同一个使用者吗? - Can I bind multiple queues to the same consumer in rabbitMQ and spring boot? 春季引导RabbitMQ中发送方和接收方的最低要求配置是什么? - What are the minimum required configurations at sender side and receiver side in spring boot RabbitMQ? 如何使用@KafkaListener spring 引导 2 消费者获取消费者 ID - How to get consumer-id using a @KafkaListener spring boot 2 consumer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM