List of usage examples for org.springframework.amqp.rabbit.listener.adapter MessageListenerAdapter MessageListenerAdapter
public MessageListenerAdapter(Object delegate)
From source file:com.anton.dev.tqrbs2.basic.BasicJava.java
public static void main(String[] args) throws Exception { ConnectionFactory cf = new CachingConnectionFactory(); // set up the queue, exchange, binding on the broker RabbitAdmin admin = new RabbitAdmin(cf); Queue queue = new Queue("myQueue"); admin.declareQueue(queue);//from w w w. j a v a 2s . com TopicExchange exchange = new TopicExchange("myExchange2"); admin.declareExchange(exchange); admin.declareBinding(BindingBuilder.bind(queue).to(exchange).with("foo.*")); // set up the listener and container SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(cf); Object listener = new Object() { public void handleMessage(String foo) { LOGGER.info("Recibiendo Java: " + foo); } }; MessageListenerAdapter adapter = new MessageListenerAdapter(listener); container.setMessageListener(adapter); container.setQueueNames("myQueue"); container.start(); // send something RabbitTemplate template = new RabbitTemplate(cf); String msg = "Hello, world Rabbit!"; LOGGER.info("Enviando Java: " + msg); template.convertAndSend("myExchange2", "foo.bar", msg); Thread.sleep(1000); container.stop(); }
From source file:com.anton.dev.tqrbs2.QueueConsumeProcess.java
private void consume() { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setConnectionFactory(connectionFactory); container.setQueueNames("test.queue.1", "test.queue.2", "test.queue.3", "test.queue.4", "test.queue.5"); container.setMessageListener(new MessageListenerAdapter(this)); container.start();// w w w. j a v a 2s . c o m }
From source file:limey.git.amqp.SampleAmqpSimpleApplication.java
@Bean public SimpleMessageListenerContainer container() { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(this.connectionFactory); Object listener = new Object() { @SuppressWarnings("unused") public void handleMessage(String foo) { System.out.println(foo); }//from w w w .j av a 2 s . c om }; MessageListenerAdapter adapter = new MessageListenerAdapter(listener); container.setMessageListener(adapter); container.setQueueNames("foo"); return container; }
From source file:de.msg.message.amqp.AmqpConfiguration.java
@Bean public MessageListenerAdapter listenerAdapter(AmqpReceiver receiver) { return new MessageListenerAdapter(receiver); }
From source file:be.rufer.playground.amqpclient.config.RabbitConfig.java
public MessageListener createMessageListenerAdapter() { MessageListenerAdapter messageListenerAdapter = new MessageListenerAdapter(new MessageHandler()); messageListenerAdapter.setDefaultListenerMethod("sendMessageBySms"); return messageListenerAdapter; }
From source file:org.farrukh.examples.amqp.Application.java
/** * Custom message listener./*ww w . ja v a 2s .co m*/ * @param messageHandler an message object handler. * @return message listener adapter */ @Bean public MessageListener messageListener(final CustomMessageHandler messageHandler) { return new MessageListenerAdapter(messageHandler); }
From source file:com.nayidisha.slowglow.config.SpringMessagingConfig.java
/** * Wraps our LoggingHandler in a MessageListenerAdapter to be used by a * MessageListenerContainer/* ww w .ja v a2 s. c om*/ * * @return */ @Bean(name = "loggingMessageListenerAdapter") public MessageListenerAdapter loggingMessageListenerAdapter() { MessageListenerAdapter adapter = new MessageListenerAdapter(loggingHandler()); return adapter; }
From source file:org.resthub.rpc.RPCEndpoint.java
/** * Starts the endpoint on the connection specified. * A listener container is launched on a created queue. The listener will * respond to hessian requests. The endpoint is closed by calling the destroy * method.//from w w w .j a v a 2 s. co m */ public void run() { logger.debug("Launching endpoint for service : " + serviceAPI.getSimpleName()); admin = new RabbitAdmin(connectionFactory); // Add connectionListener to recreate queue when connection fall connectionFactory.addConnectionListener(new ConnectionListener() { public void onCreate(Connection connection) { createQueue(admin, getRequestQueueName(serviceAPI)); } public void onClose(Connection connection) { } }); // Create the queue normaly the first time this.createQueue(admin, getRequestQueueName(serviceAPI)); MessageListenerAdapter listenerAdapter = new MessageListenerAdapter( new RawMessageDelegate(serviceAPI, serviceImpl, serializationHandler)); listenerAdapter.setMessageConverter(null); listenerAdapter.setMandatoryPublish(false); listenerContainer = new SimpleMessageListenerContainer(); listenerContainer.setConnectionFactory(connectionFactory); listenerContainer.setQueueNames(getRequestQueueName(serviceAPI)); listenerContainer.setMessageListener(listenerAdapter); if (this.concurentConsumers > 0) { listenerContainer.setConcurrentConsumers(concurentConsumers); } listenerContainer.start(); }
From source file:org.resthub.rpc.HessianEndpoint.java
/** * Starts the endpoint on the connection specified. * A listener container is launched on a created queue. The listener will * respond to hessian requests. The endpoint is closed by calling the destroy * method./* ww w. j a v a 2 s . c o m*/ */ public void run() { logger.debug("Launching endpoint for service : " + serviceAPI.getSimpleName()); admin = new RabbitAdmin(connectionFactory); // Add connectionListener to recreate queue when connection fall connectionFactory.addConnectionListener(new ConnectionListener() { public void onCreate(Connection connection) { createQueue(admin, getRequestQueueName(serviceAPI)); } public void onClose(Connection connection) { } }); // Create the queue normaly the first time this.createQueue(admin, getRequestQueueName(serviceAPI)); MessageListenerAdapter listenerAdapter = new MessageListenerAdapter( new RawMessageDelegate(serviceAPI, serviceImpl, serializerFactory)); listenerAdapter.setMessageConverter(null); listenerAdapter.setMandatoryPublish(false); listenerContainer = new SimpleMessageListenerContainer(); listenerContainer.setConnectionFactory(connectionFactory); listenerContainer.setQueueNames(getRequestQueueName(serviceAPI)); listenerContainer.setMessageListener(listenerAdapter); if (this.concurentConsumers > 0) { listenerContainer.setConcurrentConsumers(concurentConsumers); } listenerContainer.start(); }
From source file:com.jbrisbin.groovy.mqdsl.RabbitMQBuilder.java
@Override public Object invokeMethod(String methodName, Object args) { if (CONSUME.equals(methodName)) { Consume consume = new Consume(); SimpleMessageListenerContainer listenerContainer = consume.getListenerContainer(); Object[] params = (Object[]) args; for (Object param : params) { if (param instanceof Map) { Map paramMap = (Map) param; if (paramMap.containsKey(ON_MESSAGE)) { Object onMessage = paramMap.get(ON_MESSAGE); if (onMessage instanceof String) { consume.setEventName((String) onMessage); } else if (onMessage instanceof Closure) { consume.setDelegate((Closure) onMessage); } else if (onMessage instanceof MessageListener) { listenerContainer.setMessageListener(onMessage); } else { listenerContainer.setMessageListener(new MessageListenerAdapter(onMessage)); }//from w w w . j a v a 2 s. com } if (paramMap.containsKey(ACK)) { AcknowledgeMode mode = AcknowledgeMode.valueOf(paramMap.get(ACK).toString().toUpperCase()); listenerContainer.setAcknowledgeMode(mode); } else { listenerContainer.setAcknowledgeMode(AcknowledgeMode.AUTO); } } else if (param instanceof Closure) { consume.setDelegate((Closure) param); } } listenerContainer.setQueues(currentQueue); listenerContainer.afterPropertiesSet(); listenerContainer.start(); listenerContainers.add(listenerContainer); return super.invokeMethod(methodName, consume); } else if (PUBLISH.equals(methodName)) { Publish publish = new Publish(); publish.invokeMethod(CALL, args); return super.invokeMethod(methodName, publish); } return super.invokeMethod(methodName, args); }