繁体   English   中英

使用Spring Cloud Stream将RabbitMQ使用者绑定到RabbitMQ生产者

[英]Bind RabbitMQ consumer using Spring Cloud Stream to RabbitMQ producer

我有两种微服务,一种用于从内部FTP服务器收集XML文件,将其转换为DTO对象,然后将它们作为字节发布到RabbitMQ中,另一种用于反序列化从RabbitMQ到DTO对象的传入字节,将它们映射到JPA实体并持久化。到数据库。

我想在这两个微服务之间配置RabbitMQ代理,如下所示:

1)对于收集XML文件的微服务,我在application.properties中进行了如下编辑:

spring.cloud.stream.bindings.output.destination=TOPIC
spring.cloud.stream.bindings.output.group=proactive-policy

2)对于持久保留传入DTO触发的微服务,我在application.properties中配置如下:

spring.cloud.stream.bindings.input.destination=TOPIC
spring.cloud.stream.bindings.input.group=proactive-policy 

为了从RabbitMQ接收传入的字节,我正在使用第二个微服务作为接收器:

@EnableJpaAuditing
@EnableBinding(Sink.class)
@SpringBootApplication(scanBasePackages = { "org.proactive.policy.data.cache" })
@RefreshScope
public class ProactivePolicyDataCacheApplication {
    private static Logger logger = LoggerFactory.getLogger(ProactivePolicyDataCacheApplication.class);

    @Autowired
    PolicyService policyService;

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

    @StreamListener(Sink.INPUT)
    public void input(Message<byte[]> message) throws Exception {
        if (Objects.isNull(message) || Objects.isNull(message.getPayload())) {
            logger.error("the message is null ");
            throw new IllegalArgumentException("`message` and `message.payload` cannot be null");
        }
        byte[] data = message.getPayload();
        if (data.length == 0) {
            logger.warn("Received empty message");
            return;
        }
        logger.info("Got data from policy-collector = " + new String(data, "UTF-8"));
        PolicyListDto policyListDto = (PolicyListDto) SerializationUtils.deserialize(data);
        logger.info("Policies.xml from policy-collector = " + policyListDto.getPolicy().toString());

        policyService.save(policyListDto);
    }

}

但是,当我打开RabbitMQ控制台查看交易时,队列TOPIC.proactive-policy中什么都没收到,但是传入的消息是在我没有配置的另一个队列FTPSTREAM.proactive-policy-collector中收到的

是否有解决此问题的建议

要点:1.输出绑定没有“组”之类的东西。 消费群体是一种消费财产。 这是javadocs的片段。

/**
 * Unique name that the binding belongs to (applies to consumers only). Multiple
 * consumers within the same group share the subscription. A null or empty String
 * value indicates an anonymous group that is not shared.
 * @see org.springframework.cloud.stream.binder.Binder#bindConsumer(java.lang.String,
 * java.lang.String, java.lang.Object,
 * org.springframework.cloud.stream.binder.ConsumerProperties)
 */
private String group;

2.名称“ FTPSTREAM.proactive-policy-collector”绝对不是spring-cloud-stream生成的,因此请考虑查看您的配置并查看错过的内容。

它告诉我,您有一些使用其“目标”的用户名为FTPSTREAM,并使用其“组”的proactive-policy-collector 它还告诉我,您的生产者将消息发送到FTPSTREAM交换机。

暂无
暂无

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

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