Commit 6fb45c0e authored by yanzg's avatar yanzg

消费者自动创建

parent c74223b1
...@@ -2,6 +2,7 @@ package com.yanzuoguang.mq.base; ...@@ -2,6 +2,7 @@ package com.yanzuoguang.mq.base;
import com.yanzuoguang.mq.base.consumer.ConsumerSimpleMessageListenerContainer; import com.yanzuoguang.mq.base.consumer.ConsumerSimpleMessageListenerContainer;
import org.springframework.amqp.rabbit.connection.ConnectionFactory; import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.ChannelAwareMessageListener;
import org.springframework.amqp.rabbit.core.RabbitAdmin; import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer; import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter; import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
...@@ -21,12 +22,12 @@ public class MqConsumeDynamic { ...@@ -21,12 +22,12 @@ public class MqConsumeDynamic {
@Value("${yzg.onOfConsumer:10}") @Value("${yzg.onOfConsumer:10}")
private int onOfConsumer; private int onOfConsumer;
public SimpleMessageListenerContainer init(String queueName, Object target, String methodName) { public SimpleMessageListenerContainer init(String queueName, ChannelAwareMessageListener messageListener) {
ConsumerSimpleMessageListenerContainer container = new ConsumerSimpleMessageListenerContainer(); ConsumerSimpleMessageListenerContainer container = new ConsumerSimpleMessageListenerContainer();
container.setConnectionFactory(connectionFactory); container.setConnectionFactory(connectionFactory);
container.setQueueNames(queueName); container.setQueueNames(queueName);
container.setConcurrentConsumers(onOfConsumer); container.setConcurrentConsumers(onOfConsumer);
container.setMessageListener(new MessageListenerAdapter(target, methodName)); container.setMessageListener(new MessageListenerAdapter(messageListener));
container.start(); container.start();
return container; return container;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment