org.springframework.amqp.rabbit.core.ChannelAwareMessageListener Java Examples

The following examples show how to use org.springframework.amqp.rabbit.core.ChannelAwareMessageListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RabbitMQConfig.java    From jim-framework with Apache License 2.0 6 votes vote down vote up
@Bean
public SimpleMessageListenerContainer messageContainer() {
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory());
    container.setQueues(queue());
    container.setExposeListenerChannel(true);
    container.setMaxConcurrentConsumers(1);
    container.setConcurrentConsumers(1);
    container.setAcknowledgeMode(AcknowledgeMode.MANUAL);
    container.setMessageListener(new ChannelAwareMessageListener() {

        public void onMessage(Message message, com.rabbitmq.client.Channel channel) throws Exception {
            byte[] body = message.getBody();
            logger.info("消费端接收到消息 : " + new String(body));
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        }
    });
    return container;
}
 
Example #2
Source File: RabbitConfig.java    From notes with Apache License 2.0 5 votes vote down vote up
/**
     * 创建制定的 监听容器
     *
     * @param queueName  监听的队列名字
     * @param listenerChannel 设置是否将监听的频道 公开给已注册的
     * @param PrefetchCount  告诉代理一次请求多少条消息过来
     * @param ConcurrentConsumers  制定创建多少个并发的消费者数量
     * @param acknowledgeMode  消息确认模式
     * @param listener 监听器
     * @return org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer
     * @author fruiqi
     * @date 19-2-11 下午4:13
     **/
    public SimpleMessageListenerContainer setSimpleMessageListenerContainer(String queueName, boolean listenerChannel,
                                                                            int PrefetchCount, int ConcurrentConsumers,
                                                                            AcknowledgeMode acknowledgeMode,
                                                                            ChannelAwareMessageListener listener) throws Exception {
        SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(getConnection());
//        container.setQueueNames(getMACAddressRrefix(queueName));
        container.setQueueNames(queueName);
        container.setExposeListenerChannel(listenerChannel);
        container.setPrefetchCount(PrefetchCount);
        container.setConcurrentConsumers(ConcurrentConsumers);
        container.setAcknowledgeMode(acknowledgeMode);
        container.setMessageListener(listener);
        return container;
    }