List of usage examples for org.springframework.amqp.core MessageProperties getReplyTo
public String getReplyTo()
From source file:com.jbrisbin.vpc.jobsched.mapred.MapReduceMessageConverter.java
public Object fromMessage(Message message) throws MessageConversionException { MessageProperties props = message.getMessageProperties(); if (isAuthorized(props)) { //Map<String, Object> headers = props.getHeaders(); byte[] bytes = message.getBody(); MapReduceMessage msg = new MapReduceMessage(); msg.setId(new String(props.getCorrelationId())); try {//from w w w . j ava 2 s . c om msg.setReplyTo(props.getReplyTo().toString()); } catch (NullPointerException ignored) { } msg.setKey(props.getHeaders().get("mapreduce.key").toString()); msg.setSrc(props.getHeaders().get("mapreduce.src").toString()); msg.setType(props.getReceivedRoutingKey()); try { try { msg.setData(mapObject(bytes, List.class)); } catch (JsonMappingException e1) { try { msg.setData(mapObject(bytes, Map.class)); } catch (JsonMappingException e2) { try { msg.setData(mapObject(bytes, Integer.class)); } catch (JsonMappingException e3) { try { msg.setData(mapObject(bytes, String.class)); } catch (JsonMappingException e4) { } } } } } catch (IOException ioe) { throw new MessageConversionException(ioe.getMessage(), ioe); } return msg; } else { throw new MessageConversionException("Invalid security key."); } }
From source file:com.jbrisbin.vpc.jobsched.sql.SqlMessageConverter.java
public Object fromMessage(Message message) throws MessageConversionException { MessageProperties props = message.getMessageProperties(); if (isAuthorized(props)) { //Map<String, Object> headers = props.getHeaders(); byte[] bytes = message.getBody(); SqlMessage msg;//from www . j av a2s . c om try { msg = mapObject(bytes, SqlMessage.class); msg.setId(new String(props.getCorrelationId())); msg.setReplyTo(props.getReplyTo().toString()); if (log.isDebugEnabled()) { log.debug(String.format(" MSG: %s", msg)); } } catch (IOException e) { throw new MessageConversionException(e.getMessage(), e); } return msg; } else { throw new MessageConversionException("Invalid security key."); } }
From source file:com.ushahidi.swiftriver.core.rules.DropFilterQueueConsumerTest.java
@Test public void onMessage() throws Exception { Message mockMessage = mock(Message.class); Channel mockChannel = mock(Channel.class); MessageProperties mockMessageProperties = mock(MessageProperties.class); String dropJSON = "{\"source\":\"semantics\",\"identity_orig_id\": \"http://feeds.bbci.co.uk/news/rss.xml\", \"droplet_raw\": \"The danger of growing resistance to antibiotics should be treated as seriously as the threat of terrorism, England's chief medical officer says.\", \"droplet_orig_id\": \"c558d88a44fc70da36d04746574e05e4\", \"droplet_locale\": \"en-gb\", \"identity_username\": \"http://www.bbc.co.uk/news/#sa-ns_mchannel=rss&ns_source=PublicRSS20-sa\", \"droplet_date_pub\": \"Mon, 11 Mar 2013 07:32:59 +0000\", \"droplet_type\": \"original\", \"identity_avatar\": \"http://news.bbcimg.co.uk/nol/shared/img/bbc_news_120x60.gif\", \"droplet_title\": \"Antibiotic resistance 'threat to UK'\", \"links\": [{\"url\": \"http://www.bbc.co.uk/news/health-21737844#sa-ns_mchannel=rss&ns_source=PublicRSS20-sa\", \"original_url\": true}], \"droplet_content\": \"The danger of growing resistance to antibiotics should be treated as seriously as the threat of terrorism, England's chief medical officer says.\", \"identity_name\": \"BBC News - Home\", \"channel\": \"rss\", \"river_id\": [2], \"bucket_id\": []}"; when(mockMessage.getBody()).thenReturn(dropJSON.getBytes()); when(mockMessage.getMessageProperties()).thenReturn(mockMessageProperties); when(mockMessageProperties.getReplyTo()).thenReturn("reply-to-queue"); when(mockMessageProperties.getCorrelationId()).thenReturn("drop-correlation-id".getBytes()); // Send the drop to the rules executor dropFilterQueueConsumer.onMessage(mockMessage, mockChannel); ArgumentCaptor<RawDrop> dropArgument = ArgumentCaptor.forClass(RawDrop.class); ArgumentCaptor<String> routingKeyArgument = ArgumentCaptor.forClass(String.class); ArgumentCaptor<MessagePostProcessor> postProcessorArgument = ArgumentCaptor .forClass(MessagePostProcessor.class); verify(mockRulesExecutor).applyRules(dropArgument.capture(), rulesMapArgument.capture()); verify(mockAmqpTemplate).convertAndSend(routingKeyArgument.capture(), dropArgument.capture(), postProcessorArgument.capture()); String routingKey = routingKeyArgument.getValue(); assertEquals("reply-to-queue", routingKey); RawDrop drop = dropArgument.getValue(); assertEquals("rules", drop.getSource()); }
From source file:org.springframework.amqp.rabbit.AsyncRabbitTemplate.java
private String getOrSetCorrelationIdAndSetReplyTo(Message message) { String correlationId;/*from ww w . ja va 2s . c om*/ MessageProperties messageProperties = message.getMessageProperties(); Assert.notNull(messageProperties, "the message properties cannot be null"); String currentCorrelationId = messageProperties.getCorrelationId(); if (!StringUtils.hasText(currentCorrelationId)) { correlationId = UUID.randomUUID().toString(); messageProperties.setCorrelationId(correlationId); Assert.isNull(messageProperties.getReplyTo(), "'replyTo' property must be null"); } else { correlationId = currentCorrelationId; } messageProperties.setReplyTo(this.replyAddress); return correlationId; }
From source file:org.springframework.amqp.rabbit.core.AsyncRabbitTemplate.java
private String getOrSetCorrelationIdAndSetReplyTo(Message message) { String correlationId;//from w w w . jav a 2 s . c o m MessageProperties messageProperties = message.getMessageProperties(); Assert.notNull(messageProperties, "the message properties cannot be null"); byte[] currentCorrelationId = messageProperties.getCorrelationId(); if (currentCorrelationId == null) { correlationId = UUID.randomUUID().toString(); messageProperties.setCorrelationId(correlationId.getBytes(this.charset)); Assert.isNull(messageProperties.getReplyTo(), "'replyTo' property must be null"); } else { correlationId = new String(currentCorrelationId, this.charset); } messageProperties.setReplyTo(this.replyAddress); return correlationId; }
From source file:org.springframework.amqp.rabbit.support.RabbitUtils.java
public static BasicProperties extractBasicProperties(Message message, String charset) { if (message == null || message.getMessageProperties() == null) { return null; }/* w w w . j a va 2 s . co m*/ MessageProperties source = message.getMessageProperties(); BasicProperties target = new BasicProperties(); target.setHeaders(source.getHeaders()); target.setTimestamp(source.getTimestamp()); target.setMessageId(source.getMessageId()); target.setUserId(source.getUserId()); target.setAppId(source.getAppId()); target.setClusterId(source.getClusterId()); target.setType(source.getType()); MessageDeliveryMode deliveryMode = source.getDeliveryMode(); if (deliveryMode != null) { target.setDeliveryMode(MessageDeliveryMode.toInt(deliveryMode)); } target.setExpiration(source.getExpiration()); target.setPriority(source.getPriority()); target.setContentType(source.getContentType()); target.setContentEncoding(source.getContentEncoding()); byte[] correlationId = source.getCorrelationId(); if (correlationId != null && correlationId.length > 0) { try { target.setCorrelationId(new String(correlationId, charset)); } catch (UnsupportedEncodingException ex) { throw new AmqpUnsupportedEncodingException(ex); } } Address replyTo = source.getReplyTo(); if (replyTo != null) { target.setReplyTo(replyTo.toString()); } return target; }