List of usage examples for org.springframework.amqp.core MessageProperties getReceivedRoutingKey
public String getReceivedRoutingKey()
From source file:com.ushahidi.swiftriver.core.rules.RulesUpdateQueueConsumerTest.java
@Test public void onDeleteRuleMessage() throws Exception { Message mockMessage = mock(Message.class); Channel mockChannel = mock(Channel.class); MessageProperties mockMessageProperties = mock(MessageProperties.class); String messageBody = "{\"id\": 1, \"river_id\": 20, \"conditions\": [{\"field\": \"title\", \"operator\": \"contains\", \"value\": \"kenya\"}], \"actions\": [{\"addToBucket\": 2}], \"all_conditions\": false}"; when(mockMessage.getBody()).thenReturn(messageBody.getBytes()); when(mockMessage.getMessageProperties()).thenReturn(mockMessageProperties); when(mockMessageProperties.getReceivedRoutingKey()).thenReturn("web.river.rules.delete"); rulesUpdateQueueConsumer.onMessage(mockMessage, mockChannel); ArgumentCaptor<Rule> ruleArgument = ArgumentCaptor.forClass(Rule.class); verify(rulesRegistry).deleteRule(ruleArgument.capture()); }
From source file:com.ushahidi.swiftriver.core.rules.RulesUpdateQueueConsumerTest.java
@Test public void onUpdateRuleMessage() throws Exception { Message mockMessage = mock(Message.class); Channel mockChannel = mock(Channel.class); MessageProperties mockMessageProperties = mock(MessageProperties.class); String messageBody = "{\"id\": 1, \"river_id\": 20, \"conditions\": [{\"field\": \"title\", \"operator\": \"contains\", \"value\": \"kenya\"}], \"actions\": [{\"addToBucket\": 2}], \"all_conditions\": true}"; when(mockMessage.getBody()).thenReturn(messageBody.getBytes()); when(mockMessage.getMessageProperties()).thenReturn(mockMessageProperties); when(mockMessageProperties.getReceivedRoutingKey()).thenReturn("web.river.rules.update"); rulesUpdateQueueConsumer.onMessage(mockMessage, mockChannel); ArgumentCaptor<Rule> ruleArgument = ArgumentCaptor.forClass(Rule.class); verify(rulesRegistry).updateRule(ruleArgument.capture()); }
From source file:com.ushahidi.swiftriver.core.rules.RulesUpdateQueueConsumerTest.java
@Test public void onAddRuleMessage() throws Exception { Message mockMessage = mock(Message.class); Channel mockChannel = mock(Channel.class); MessageProperties mockMessageProperties = mock(MessageProperties.class); String messageBody = "{\"id\": 1, \"river_id\": 20, \"conditions\": [{\"field\": \"title\", \"operator\": \"contains\", \"value\": \"kenya\"}], \"actions\": [{\"addToBucket\": 2}], \"all_conditions\": false}"; when(mockMessage.getBody()).thenReturn(messageBody.getBytes()); when(mockMessage.getMessageProperties()).thenReturn(mockMessageProperties); when(mockMessageProperties.getReceivedRoutingKey()).thenReturn("web.river.rules.add"); rulesUpdateQueueConsumer.onMessage(mockMessage, mockChannel); ArgumentCaptor<Rule> ruleArgument = ArgumentCaptor.forClass(Rule.class); verify(rulesRegistry).addRule(ruleArgument.capture()); Rule rule = ruleArgument.getValue(); assertEquals(1L, rule.getId());/*from w w w. j av a 2 s . c om*/ assertEquals(20L, rule.getRiverId()); }
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 av a2 s . co m*/ 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.RequeueListener.java
@Override public void onMessage(Message message, Channel channel) throws Exception { MessageProperties props = message.getMessageProperties(); Map<String, Object> headers = props.getHeaders(); int requeued = 0; if (headers.containsKey(REQUEUED)) { requeued = (Integer) headers.get(REQUEUED); }/*from w w w . ja v a2s. c om*/ long delay = retryDelays[requeued]; if (requeued < maxRetries) { headers.put(REQUEUED, requeued + 1); Object exchange = headers.get("exchange"); if (null == exchange) { exchange = props.getReceivedExchange(); } else { headers.remove("exchange"); } Object route = headers.get("route"); if (null == route) { route = props.getReceivedRoutingKey(); } else { headers.remove("route"); } log.info(String.format("Requeing message %s in %s...", new String(props.getCorrelationId()), convertMillis(delay))); timer.schedule(new DelayedSend(message, exchange.toString(), route.toString()), delay); } }