List of usage examples for org.springframework.amqp.rabbit.listener SimpleMessageListenerContainer setMessageListener
public void setMessageListener(MessageListener messageListener)
From source file:com.jbrisbin.vpc.jobsched.mapred.MapReduceMessageHandler.java
private void listenForReReduce(MapReduceMessage msg) throws ScriptException, ResourceException { String hash = "rereduce." + DigestUtils.md5Hex(msg.getId()); Queue q = new Queue(hash); q.setExclusive(true);//from ww w .j av a 2 s .c o m q.setDurable(false); q.setAutoDelete(true); rabbitAdmin.declareQueue(q); SimpleMessageListenerContainer c = new SimpleMessageListenerContainer(connectionFactory); c.setQueues(q); c.setMessageListener(new ReReduceListener(msg)); c.start(); listenerCache.put(hash, c); }
From source file:org.openbaton.nse.api.EventReceiver.java
@Bean public SimpleMessageListenerContainer setCreationMessageContainer(ConnectionFactory connectionFactory, @Qualifier("getCreationQueue") Queue queue, @Qualifier("setCreationMessageListenerAdapter") MessageListenerAdapter adapter) { logger.debug("Created MessageContainer for NSR Creation event"); SimpleMessageListenerContainer res = new SimpleMessageListenerContainer(); res.setConnectionFactory(connectionFactory); res.setQueues(queue);/*from w ww .ja v a 2 s .c o m*/ res.setMessageListener(adapter); return res; }
From source file:org.openbaton.nse.api.EventReceiver.java
@Bean public SimpleMessageListenerContainer setErrorMessageContainer(ConnectionFactory connectionFactory, @Qualifier("getErrorQueue") Queue queue, @Qualifier("setErrorMessageListenerAdapter") MessageListenerAdapter adapter) { logger.debug("Created MessageContainer for NSR error event"); SimpleMessageListenerContainer res = new SimpleMessageListenerContainer(); res.setConnectionFactory(connectionFactory); res.setQueues(queue);//ww w. j a va 2s . c om res.setMessageListener(adapter); return res; }
From source file:org.openbaton.nse.api.EventReceiver.java
@Bean public SimpleMessageListenerContainer setScaleMessageContainer(ConnectionFactory connectionFactory, @Qualifier("getScaleQueue") Queue queue, @Qualifier("setScaleMessageListenerAdapter") MessageListenerAdapter adapter) { logger.debug("Created MessageContainer for NSR scale event"); SimpleMessageListenerContainer res = new SimpleMessageListenerContainer(); res.setConnectionFactory(connectionFactory); res.setQueues(queue);/*from ww w .j a v a 2 s. co m*/ res.setMessageListener(adapter); return res; }
From source file:com.jbrisbin.vpc.jobsched.SubmitClosure.java
@Override public Object call(Object[] args) { log.debug("args: " + args); String exch = args[0].toString(); String route = args[1].toString(); final Object body = args[2]; Map headers = null;/*from w w w.j a va 2 s . c o m*/ final BlockingQueue<Object> resultsQueue = new LinkedBlockingQueue<Object>(); Queue replyQueue = rabbitAdmin.declareQueue(); SimpleMessageListenerContainer listener = new SimpleMessageListenerContainer(); listener.setQueues(replyQueue); if (args.length > 3) { for (int i = 3; i <= args.length; i++) { if (args[i] instanceof MessageListener) { MessageListener callback = (MessageListener) args[3]; listener.setMessageListener(callback); } else if (args[i] instanceof Map) { headers = (Map) args[i]; } } } else { listener.setMessageListener(new MessageListener() { public void onMessage(Message message) { byte[] body = message.getBody(); try { resultsQueue.add(mapper.readValue(body, 0, body.length, Map.class)); } catch (IOException e) { log.error(e.getMessage(), e); } } }); } final Map msgHdrs = headers; rabbitTemplate.send(exch, route, new MessageCreator() { public Message createMessage() { MessageProperties props = new RabbitMessageProperties(); props.setContentType("application/json"); if (null != msgHdrs) { props.getHeaders().putAll(msgHdrs); } String uuid = UUID.randomUUID().toString(); props.setCorrelationId(uuid.getBytes()); ByteArrayOutputStream out = new ByteArrayOutputStream(); try { mapper.writeValue(out, body); } catch (IOException e) { log.error(e.getMessage(), e); } Message msg = new Message(out.toByteArray(), props); return msg; } }); Object results = null; try { results = resultsQueue.poll(5, TimeUnit.SECONDS); } catch (InterruptedException e) { log.error(e.getMessage(), e); } listener.stop(); return results; }
From source file:org.openbaton.common.vnfm_sdk.amqp.configuration.RabbitConfiguration.java
@Bean SimpleMessageListenerContainer container_emsRegistrator(ConnectionFactory connectionFactory) { if (listenerAdapter_emsRegistrator != null) { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setConnectionFactory(connectionFactory); container.setQueueNames(queueName_emsRegistrator); container.setConcurrentConsumers(1); container.setMaxConcurrentConsumers(15); container.setMessageListener(listenerAdapter_emsRegistrator); return container; } else//from w w w .j av a2 s . co m return null; }
From source file:org.openbaton.common.vnfm_sdk.amqp.configuration.RabbitConfiguration.java
@Bean SimpleMessageListenerContainer container_eventRegister(ConnectionFactory connectionFactory, @Qualifier("listenerAdapter_nfvoGenericActions") MessageListenerAdapter listenerAdapter) { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setConnectionFactory(connectionFactory); container.setQueueNames(queueName_nfvoGenericActions); if (minConcurrency <= 0 || maxConcurrency <= 0 || minConcurrency > maxConcurrency) { container.setConcurrentConsumers(5); container.setMaxConcurrentConsumers(15); } else {// w ww .j a va 2 s . co m container.setConcurrentConsumers(minConcurrency); container.setMaxConcurrentConsumers(maxConcurrency); } container.setMessageListener(listenerAdapter); return container; }
From source file:org.openbaton.common.vnfm_sdk.amqp.configuration.RabbitConfiguration.java
@Bean SimpleMessageListenerContainer container_logDispatcher(ConnectionFactory connectionFactory, @Qualifier("listenerAdapter_logDispatch") MessageListenerAdapter listenerAdapter) { if (listenerAdapter != null) { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setConnectionFactory(connectionFactory); container.setQueueNames(queueName_logDispatch); if (minConcurrency <= 0 || maxConcurrency <= 0 || minConcurrency > maxConcurrency) { container.setConcurrentConsumers(5); container.setMaxConcurrentConsumers(15); } else {/*from ww w . j a va 2 s . c o m*/ container.setConcurrentConsumers(minConcurrency); container.setMaxConcurrentConsumers(maxConcurrency); } container.setMessageListener(listenerAdapter); return container; } else return null; }
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)); }/*ww w . j a va2 s.co m*/ } 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); }
From source file:io.acme.solution.query.conf.EventBusConfigurer.java
@PostConstruct private void setup() { Queue currentQueue = null;// w ww .j a v a 2 s . c o m SimpleMessageListenerContainer currentContainer = null; MessageListenerAdapter currentAdapter = null; final RabbitAdmin rabbitAdmin = this.context.getBean("eventBusRabbitAdmin", RabbitAdmin.class); final ConnectionFactory connectionFactory = this.context.getBean("eventBusConnectionFactory", ConnectionFactory.class); final TopicExchange exchange = this.context.getBean("eventExchange", TopicExchange.class); final MessageConverter converter = this.context.getBean("eventBusMessageConverter", MessageConverter.class); final Map<String, EventHandler> eventHandlersRegistry = EventHandlerUtils .buildEventHandlersRegistry(this.handlerBasePackage, this.context); for (String eventType : eventHandlersRegistry.keySet()) { rabbitAdmin.declareQueue(currentQueue = new Queue(this.queuePrefix + eventType)); rabbitAdmin.declareBinding(BindingBuilder.bind(currentQueue).to(exchange).with(eventType)); currentAdapter = new MessageListenerAdapter(eventHandlersRegistry.get(eventType), converter); currentContainer = new SimpleMessageListenerContainer(connectionFactory); currentContainer.setMessageListener(currentAdapter); currentContainer.setQueues(currentQueue); currentContainer.start(); } }