小编BIn*_*hav的帖子

Spring AMQP-发送者和接收消息

我在从RabbitMQ接收消息时遇到问题。我正在发送如下消息

        HashMap<Object, Object> senderMap=new HashMap<>();
        senderMap.put("STATUS", "SUCCESS");
        senderMap.put("EXECUTION_START_TIME", new Date());

        rabbitTemplate.convertAndSend(Constants.ADAPTOR_OP_QUEUE,senderMap);
Run Code Online (Sandbox Code Playgroud)

如果在RabbitMQ中看到,我们将获得完全合格的类型。

在当前情况下,同一消费者有n个生产者。如果我使用任何映射器,则会导致异常。我将如何发送消息,使其不包含任何type_id,并且可以将消息作为Message对象接收,以后可以将其绑定到接收器中的自定义对象。

我收到如下消息。您能否让我知道如何使用Jackson2MessageConverter,以便消息将直接从Receiver端绑定到我的Object / HashMap。我也已经从发件人中删除了Type_ID。

消息在RabbitMQ中的外观

优先级:0 delivery_mode:2个标头:
ContentTypeId:java.lang.Object KeyTypeId:java.lang.Object content_encoding:UTF-8 content_type:application / json {“ Execution_start_time”:1473747183636,“ status”:“ SUCCESS”}

@Component
public class AdapterOutputHandler {

    private static Logger logger = Logger.getLogger(AdapterOutputHandler.class);

    @RabbitListener(containerFactory="adapterOPListenerContainerFactory",queues=Constants.ADAPTOR_OP_QUEUE)
    public void handleAdapterQueueMessage(HashMap<String,Object> message){

        System.out.println("Receiver:::::::::::"+message.toString());

    }

}
Run Code Online (Sandbox Code Playgroud)

连接

@Bean(name="adapterOPListenerContainerFactory")
    public SimpleRabbitListenerContainerFactory adapterOPListenerContainerFactory() {
        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
        factory.setConnectionFactory(connectionFactory());
        Jackson2JsonMessageConverter messageConverter = new Jackson2JsonMessageConverter();
        DefaultClassMapper classMapper = new DefaultClassMapper();
        messageConverter.setClassMapper(classMapper);
        factory.setMessageConverter(messageConverter);

    }
Run Code Online (Sandbox Code Playgroud)

例外

Caused by: …
Run Code Online (Sandbox Code Playgroud)

rabbitmq spring-amqp spring-rabbitmq

8
推荐指数
1
解决办法
6340
查看次数

MessageConversionException:无法在 Spring AMQP 中解析类名

我正在尝试使用带有jackson2JsonMessageConverter. 另外,_TypeId_这里为什么显示带有类名的发件人包有什么意义?我在接收消息时遇到问题。

下面是我的配置

org.springframework.amqp.support.converter.MessageConversionException:无法解析类名。找不到类 [org.springframework.amqp.helloworld.User] 在 org.springframework.amqp.support.converter.DefaultJackson2JavaTypeMapper.getClassIdType(DefaultJackson2JavaTypeMapper.java:121) 在 org.springframework.amqp.support.converter.DefaultJackson2JavaTypeMapper.to DefaultJackson2JavaTypeMapper.java:90) 在 org.springframework.amqp.support.converter.Jackson2JsonMessageConverter.fromMessage(Jackson2JsonMessageConverter.java:145) 在 org.springframework.amqp.rabbit.listener.adapter.AbstractAdaptableMessageAbstractMessageAbstractMessage(3)在 org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter。

XML 配置

            <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
            xmlns:context="http://www.springframework.org/schema/context"
            xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:tx="http://www.springframework.org/schema/tx"
            xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:mvc="http://www.springframework.org/schema/mvc"
            xmlns:rabbit="http://www.springframework.org/schema/rabbit"
            xsi:schemaLocation="http://www.springframework.org/schema/rabbit
             http://www.springframework.org/schema/rabbit/spring-rabbit.xsd
             http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  
             http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
             http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd  
             http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd  
             http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
             http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">


            <rabbit:connection-factory id="connectionFactory"
                        channel-cache-size="25" host="10.165.18.29" username="BipUser"
                        password="bip" />

            <rabbit:queue name="Job Queue"></rabbit:queue>

            <rabbit:queue name="Input Queue"></rabbit:queue>

            <rabbit:queue name="More Info Queue"></rabbit:queue>

            <rabbit:queue name="Adaptor O/P Queue"></rabbit:queue>

            <rabbit:queue name="Command Queue"></rabbit:queue>

            <rabbit:queue name="Error Queue"></rabbit:queue>

            <bean id="simpleMessageConverter"
                        class="org.springframework.amqp.support.converter.Jackson2JsonMessageConverter">
            </bean>

            <rabbit:template …
Run Code Online (Sandbox Code Playgroud)

spring rabbitmq spring-amqp spring-boot

3
推荐指数
2
解决办法
4686
查看次数

如何在不从 CLI 中打开比较窗口之外的情况下比较两个文件夹?

我想比较两个文件夹,我所拥有的只是两个文件夹的目录路径。如何使用 Beyond Compare 4 CLI 命令来比较它们,而无需实际打开窗口。我一直在使用下面的命令,但每次都会打开窗口。

C:\Program Files\Beyond Compare 4\BCompare.exe C:\BeyondC\Folder C:\BeyondC\NoFolder /fv=Folder Compare /silent
Run Code Online (Sandbox Code Playgroud)

如何在不实际打开 BeyondCompare 窗口的情况下比较文件夹?

command-line-interface beyondcompare4

3
推荐指数
1
解决办法
3875
查看次数

对 RabbitMQ 队列的否定确认以使用 Spring AMQP 重新排队消息

我有一个应用程序,它使用 spring AMQP 为其他应用程序消费和生成消息。我有一个场景,其中发生了一些异常,我需要重新排队回到 RabbitMQ。对于一些我需要忽略的异常(基本上我需要忽略不需要重新排队的消息)

目前在下面的代码中,我已将配置设置为

factory.setDefaultRequeueRejected(false);

但我的要求是动态拒绝某些消息,并重新排队返回 RabbitMQ 以获取某些消息。

请建议

@Bean(name="rabbitListenerContainerFactory")
    public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory() {
        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
        factory.setConnectionFactory(connectionFactory());
        Jackson2JsonMessageConverter messageConverter = new Jackson2JsonMessageConverter();
        DefaultClassMapper classMapper = new DefaultClassMapper();
        Map<String, Class<?>> idClassMapping = new HashMap<String, Class<?>>();
        idClassMapping.put(Constants.JOB_TYPE_ID_, JobListenerDTO.class);
        classMapper.setIdClassMapping(idClassMapping);
        messageConverter.setClassMapper(classMapper);
        factory.setMessageConverter(messageConverter);
        factory.setDefaultRequeueRejected(false);
        factory.setReceiveTimeout(10L);
        return factory;
    }
Run Code Online (Sandbox Code Playgroud)

spring-rabbit spring-amqp

0
推荐指数
1
解决办法
2443
查看次数