use of org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer in project spring-integration by spring-projects.
the class Amqp method inboundAdapter.
/**
* Create an initial AmqpInboundChannelAdapterSpec using a
* {@link SimpleMessageListenerContainer}.
* @param connectionFactory the connectionFactory.
* @param queueNames the queueNames.
* @return the AmqpInboundChannelAdapterSpec.
*/
public static AmqpInboundChannelAdapterSMLCSpec inboundAdapter(ConnectionFactory connectionFactory, String... queueNames) {
SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer(connectionFactory);
listenerContainer.setQueueNames(queueNames);
return new AmqpInboundChannelAdapterSMLCSpec(listenerContainer);
}
use of org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer in project fru-paqx-parent by dellemc-symphony.
the class ConsumerConfig method fruRequestListenerContainer.
@Bean
SimpleMessageListenerContainer fruRequestListenerContainer() {
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(rabbitConnectionFactory);
container.setAcknowledgeMode(AcknowledgeMode.AUTO);
container.setQueues(responseQueue);
container.setAdviceChain(new Advice[] { retryPolicyAdvice() });
container.setMessageListener(fruMessageListener());
container.setErrorHandler(new DefaultContainerErrorHandler("fruRequestListenerContainer"));
return container;
}
use of org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer in project microservices by pwillhan.
the class ContainerListenerExample method main.
public static void main(String[] args) {
CachingConnectionFactory factory = new CachingConnectionFactory("localhost");
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(factory);
Object listener = new Object() {
public void handleMessage(String message) {
System.out.println("Message received: " + message);
}
};
MessageListenerAdapter adapter = new MessageListenerAdapter(listener);
container.setMessageListener(adapter);
container.setQueueNames("sample-queue");
container.start();
}
use of org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer in project spring-integration by spring-projects.
the class DispatcherHasNoSubscribersTests method testPubSub.
@Test
public void testPubSub() {
final Channel channel = mock(Channel.class);
Connection connection = mock(Connection.class);
doAnswer(invocation -> channel).when(connection).createChannel(anyBoolean());
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
when(connectionFactory.createConnection()).thenReturn(connection);
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
AmqpTemplate amqpTemplate = mock(AmqpTemplate.class);
PublishSubscribeAmqpChannel amqpChannel = new PublishSubscribeAmqpChannel("noSubscribersChannel", container, amqpTemplate);
amqpChannel.setBeanName("noSubscribersChannel");
amqpChannel.setBeanFactory(mock(BeanFactory.class));
amqpChannel.afterPropertiesSet();
List<String> logList = insertMockLoggerInListener(amqpChannel);
MessageListener listener = (MessageListener) container.getMessageListener();
listener.onMessage(new Message("Hello world!".getBytes(), null));
verifyLogReceived(logList);
}
use of org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer in project spring-integration by spring-projects.
the class DispatcherHasNoSubscribersTests method testPtP.
@SuppressWarnings("unchecked")
@Test
public void testPtP() throws Exception {
final Channel channel = mock(Channel.class);
DeclareOk declareOk = mock(DeclareOk.class);
when(declareOk.getQueue()).thenReturn("noSubscribersChannel");
when(channel.queueDeclare(anyString(), anyBoolean(), anyBoolean(), anyBoolean(), isNull())).thenReturn(declareOk);
Connection connection = mock(Connection.class);
doAnswer(invocation -> channel).when(connection).createChannel(anyBoolean());
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
when(connectionFactory.createConnection()).thenReturn(connection);
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
AmqpTemplate amqpTemplate = mock(AmqpTemplate.class);
PointToPointSubscribableAmqpChannel amqpChannel = new PointToPointSubscribableAmqpChannel("noSubscribersChannel", container, amqpTemplate);
amqpChannel.setBeanName("noSubscribersChannel");
amqpChannel.setBeanFactory(mock(BeanFactory.class));
amqpChannel.afterPropertiesSet();
MessageListener listener = (MessageListener) container.getMessageListener();
try {
listener.onMessage(new Message("Hello world!".getBytes(), null));
fail("Exception expected");
} catch (MessageDeliveryException e) {
assertThat(e.getMessage(), containsString("Dispatcher has no subscribers for amqp-channel 'noSubscribersChannel'."));
}
}
Aggregations