/** * This method will send put the transaction on a messaging queue, which will set the opening * balance of any subsequent transactions (if applicable) * * @param transaction The transaction whose subsequent transaction's opening balances need to be * updated. */ private void updateTransactionOpeningBalances( Transaction transaction, TransactionMessage.Type transactionType) { TransactionMessage transactionMessage = new TransactionMessage(); transactionMessage.setTransaction(transaction); transactionMessage.setTransactionType(transactionType); jmsTemplate.convertAndSend(SIMPLE_QUEUE, transactionMessage); }
/** 使用jmsTemplate最简便的封装convertAndSend()发送Map类型的消息. */ private void sendMessage(User user, Destination destination) { Map map = new HashMap(); map.put("userName", user.getName()); // map.put("email", user.getEmail()); map.put("email", "*****@*****.**"); jmsTemplate.convertAndSend(destination, map); }
@Test public void gatewayWithReplyChannel() { ActiveMqTestUtils.prepare(); ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("jmsGatewayWithReplyChannel.xml", this.getClass()); JmsMessageDrivenEndpoint gateway = (JmsMessageDrivenEndpoint) context.getBean("gateway"); Object replyChannel = TestUtils.getPropertyValue(gateway, "listener.gatewayDelegate.replyChannel"); assertEquals(context.getBean("replies"), replyChannel); JmsTemplate template = new JmsTemplate(context.getBean(ConnectionFactory.class)); template.convertAndSend("testDestination", "Hello"); assertNotNull(template.receive("testReplyDestination")); }
@Before public void onSetUp() throws Exception { getMessages(); // drain queue simpleJdbcTemplate.getJdbcOperations().execute("delete from T_BARS"); jmsTemplate.convertAndSend("queue", "foo"); provider = new ItemReader<String>() { public String read() { String text = (String) jmsTemplate.receiveAndConvert("queue"); list.add(text); return text; } }; retryTemplate = new RetryTemplate(); }
@Test public void testFailureAndRecovery() throws Exception { final RetryTemplate retryTemplate = new RetryTemplate(); retryTemplate.setRetryPolicy(new NeverRetryPolicy()); container.setMessageListener( new MessageListener() { @Override public void onMessage(final Message msg) { try { RetryCallback<Message> callback = new RetryCallback<Message>() { @Override public Message doWithRetry(RetryContext context) throws Exception { try { processed.add(((TextMessage) msg).getText()); } catch (JMSException e) { throw new IllegalStateException(e); } throw new RuntimeException("planned failure: " + msg); } }; RecoveryCallback<Message> recoveryCallback = new RecoveryCallback<Message>() { @Override public Message recover(RetryContext context) { try { recovered.add(((TextMessage) msg).getText()); } catch (JMSException e) { throw new IllegalStateException(e); } return msg; } }; retryTemplate.execute( callback, recoveryCallback, new DefaultRetryState(msg.getJMSMessageID())); } catch (Exception e) { throw (RuntimeException) e; } } }); container.initializeProxy(); container.start(); jmsTemplate.convertAndSend("queue", "foo"); assertEquals("foo", processed.poll(5, TimeUnit.SECONDS)); assertEquals("foo", recovered.poll(5, TimeUnit.SECONDS)); }
@Test public void testFailureAndRepresent() throws Exception { container.setMessageListener( new MessageListener() { @Override public void onMessage(Message msg) { try { processed.add(((TextMessage) msg).getText()); } catch (JMSException e) { throw new IllegalStateException(e); } throw new RuntimeException("planned failure for represent: " + msg); } }); container.initializeProxy(); container.start(); jmsTemplate.convertAndSend("queue", "foo"); for (int i = 0; i < 2; i++) { assertEquals("foo", processed.poll(5, TimeUnit.SECONDS)); } }
@Test public void testSendAndReceive() throws Exception { container.setMessageListener( new MessageListener() { @Override public void onMessage(Message msg) { try { processed.add(((TextMessage) msg).getText()); } catch (JMSException e) { throw new IllegalStateException(e); } } }); container.initializeProxy(); container.start(); jmsTemplate.convertAndSend("queue", "foo"); jmsTemplate.convertAndSend("queue", "bar"); SortedSet<String> result = new TreeSet<String>(); for (int i = 0; i < 2; i++) { result.add(processed.poll(5, TimeUnit.SECONDS)); } assertEquals("[bar, foo]", result.toString()); }
public void send(MesInfo mi) { jmsTemplate.convertAndSend(mi); }
@Scheduled(initialDelay = 1000, fixedRate = Long.MAX_VALUE) public void send() { log.info("Sending message: {}", SIMPLE_MESSAGE); jmsTemplate.convertAndSend("ExpiryQueue", SIMPLE_MESSAGE); }
private void sendMessage(String destination, String message) { JmsTemplate createJMSTemplate = createJMSTemplate(destination); createJMSTemplate.convertAndSend(message); }
@Override public void onMessage(Message message) { try { // FIXME abstraction between technology and job handling is missing CollectionJob collectionJob = (CollectionJob) simpleMessageConverter.fromMessage(message); collectionJob = protocolCollectorRegistry .getProtocolCollector(collectionJob.getService()) .collect(collectionJob); Date finishedTimestamp = new Date(); collectionJob.setFinishedTimestamp(finishedTimestamp); Map<String, MeasurementSet> measurementSets = collectionJob.getMeasurementSetsByDestination(); int val = counter.incrementAndGet(); if (val % 1000 == 0) { logger.debug("processed job #{}, {} measurement set(s)", val, measurementSets.size()); } else { logger.trace("processed job #{}, {} measurement set(s)", val, measurementSets.size()); } for (String destinationString : measurementSets.keySet()) { jmsTemplate.convertAndSend(destinationString, measurementSets.get(destinationString)); logger.info( "** sending msg '{}' to '{}'", measurementSets.get(destinationString), destinationString); } LightweightMeasurementSet errorMeasurementSet = new LightweightMeasurementSet( collectionJob.getNodeId(), collectionJob.getService(), collectionJob.getNetInterface(), collectionJob.getFinishedTimestamp()); for (String metricId : collectionJob.getAllMetrics()) { if (collectionJob.getMetricValue(metricId) == null) { errorMeasurementSet.addMeasurement( metricId, collectionJob.getMetricType(metricId), null, collectionJob.getOnmsLogicMetricId(metricId)); } logger.trace( "collected metric of job #{}='{}'", counter + ": " + metricId, collectionJob.getMetricValue(metricId)); } if (errorMeasurementSet.getMeasurements().size() > 0) { logger.warn( "result set of job #{} contains {} null values", counter, errorMeasurementSet.getMeasurements().size()); jmsTemplate.convertAndSend("error", errorMeasurementSet); logger.trace("** sending to 'error'"); } } catch (JMSException ex) { logger.error(ex.getMessage()); // FIXME react, don't continue } catch (MessageConversionException ex) { logger.error(ex.getMessage()); // FIXME react, don't continue } }
@Override public void sendMessage(Notify notify) { jmsTemplate.setMessageConverter(messageConverter); jmsTemplate.setPubSubDomain(false); jmsTemplate.convertAndSend(testQueue, notify); }
public void sendConvertedMessage(final MessageContainer container) { // TODO - fix the converter jmsTemplate.convertAndSend(SIMPLE_QUEUE, container); }