private SimpleRabbitListenerEndpoint createEndpoint(String id, String queueName) { SimpleRabbitListenerEndpoint endpoint = new SimpleRabbitListenerEndpoint(); endpoint.setId(id); endpoint.setQueueNames(queueName); return endpoint; }
@Override public void configureRabbitListeners(RabbitListenerEndpointRegistrar registrar) { SimpleRabbitListenerEndpoint endpoint = new SimpleRabbitListenerEndpoint(); endpoint.setId("myCustomEndpointId"); endpoint.setQueueNames("myQueue"); endpoint.setMessageListener(this.messageListener); registrar.registerEndpoint(endpoint); }
@Test public void registerEmptyEndpointId() { SimpleRabbitListenerEndpoint endpoint = new SimpleRabbitListenerEndpoint(); endpoint.setId(""); thrown.expect(IllegalArgumentException.class); registrar.registerEndpoint(endpoint, containerFactory); }
@Test public void registerNullContainerFactoryIsAllowed() throws Exception { SimpleRabbitListenerEndpoint endpoint = new SimpleRabbitListenerEndpoint(); endpoint.setId("some id"); registrar.setContainerFactory(containerFactory); registrar.registerEndpoint(endpoint, null); registrar.afterPropertiesSet(); assertNotNull("Container not created", registry.getListenerContainer("some id")); assertEquals("some id", registry.getListenerContainerIds().iterator().next()); assertEquals(1, registry.getListenerContainers().size()); }
@Test public void registerContainerWithoutFactory() throws Exception { SimpleRabbitListenerEndpoint endpoint = new SimpleRabbitListenerEndpoint(); endpoint.setId("myEndpoint"); registrar.setContainerFactory(containerFactory); registrar.registerEndpoint(endpoint); registrar.afterPropertiesSet(); assertNotNull("Container not created", registry.getListenerContainer("myEndpoint")); assertEquals("myEndpoint", registry.getListenerContainerIds().iterator().next()); assertEquals(1, registry.getListenerContainers().size()); }
@Override public void configureRabbitListeners(RabbitListenerEndpointRegistrar registrar) { registrar.setEndpointRegistry(customRegistry()); // Also register a custom endpoint SimpleRabbitListenerEndpoint endpoint = new SimpleRabbitListenerEndpoint(); endpoint.setId("myCustomEndpointId"); endpoint.setQueueNames("myQueue"); endpoint.setMessageListener(simpleMessageListener()); registrar.registerEndpoint(endpoint); }
@Test public void registerNullContainerFactoryWithNoDefault() throws Exception { SimpleRabbitListenerEndpoint endpoint = new SimpleRabbitListenerEndpoint(); endpoint.setId("some id"); registrar.registerEndpoint(endpoint, null); thrown.expect(IllegalStateException.class); thrown.expectMessage(endpoint.toString()); registrar.afterPropertiesSet(); }
private void registerListenerEndpoint(RabbitListenerEndpointRegistrar aRegistrar, Queue aQueue, Exchange aExchange, int aConcurrency, Object aDelegate, String aMethodName) { admin(connectionFactory).declareQueue(aQueue); admin(connectionFactory).declareBinding(BindingBuilder.bind(aQueue) .to(aExchange) .with(aQueue.getName()) .noargs()); MessageListenerAdapter messageListener = new MessageListenerAdapter(aDelegate); messageListener.setMessageConverter(jacksonAmqpMessageConverter(objectMapper)); messageListener.setDefaultListenerMethod(aMethodName); SimpleRabbitListenerEndpoint endpoint = new SimpleRabbitListenerEndpoint(); endpoint.setId(aQueue.getName()+"Endpoint"); endpoint.setQueueNames(aQueue.getName()); endpoint.setMessageListener(messageListener); aRegistrar.registerEndpoint(endpoint,createContainerFactory(aConcurrency)); }