List of usage examples for javax.jms TextMessage setJMSCorrelationID
void setJMSCorrelationID(String correlationID) throws JMSException;
From source file:test.SecureSampleApp.java
private static String sendMessage(final String encryptedMessage) { return template.execute(new SessionCallback<String>() { @Override/*from w ww . ja va 2 s . co m*/ public String doInJms(Session session) throws JMSException { TextMessage message = session.createTextMessage(encryptedMessage); Queue outQueue = session.createQueue("receive"); Destination inDest = session.createTemporaryQueue(); String correlationID = UUID.randomUUID().toString(); message.setJMSReplyTo(inDest); message.setJMSCorrelationID(correlationID); MessageProducer producer = session.createProducer(outQueue); producer.send(outQueue, message); return ((TextMessage) session.createConsumer(inDest).receive(10000)).getText(); } }, true); }
From source file:com.adaptris.core.jms.MetadataCorrelationIdSourceTest.java
public void testJmsCorrelationIdToAdaptrisMessageMetadata_NoMetadataKey() throws Exception { EmbeddedActiveMq broker = new EmbeddedActiveMq(); JmsConnection conn = broker.getJmsConnection(); try {/*from w w w.j a v a 2s .c o m*/ broker.start(); start(conn); Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE); AdaptrisMessage adpMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage(TEXT); TextMessage jmsMsg = session.createTextMessage(); jmsMsg.setJMSCorrelationID(TEXT2); MetadataCorrelationIdSource mcs = new MetadataCorrelationIdSource(); mcs.processCorrelationId(jmsMsg, adpMsg); assertNotSame(jmsMsg.getJMSCorrelationID(), adpMsg.getMetadataValue(CORRELATIONID_KEY)); session.close(); } finally { stop(conn); broker.destroy(); } }
From source file:com.adaptris.core.jms.MetadataCorrelationIdSourceTest.java
public void testJmsCorrelationIdToAdaptrisMessageMetadata() throws Exception { EmbeddedActiveMq broker = new EmbeddedActiveMq(); JmsConnection conn = broker.getJmsConnection(); try {// ww w . j a v a 2 s . c o m broker.start(); start(conn); Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE); AdaptrisMessage adpMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage(TEXT); TextMessage jmsMsg = session.createTextMessage(); jmsMsg.setJMSCorrelationID(TEXT2); MetadataCorrelationIdSource mcs = new MetadataCorrelationIdSource(CORRELATIONID_KEY); mcs.processCorrelationId(jmsMsg, adpMsg); assertEquals("Check Correlation Id Keys", jmsMsg.getJMSCorrelationID(), adpMsg.getMetadataValue(CORRELATIONID_KEY)); session.close(); } finally { stop(conn); broker.destroy(); } }
From source file:org.addsimplicity.anicetus.io.jms.JsonMessageConverter.java
/** * Translate the telemetry to a JMS message. A JMS text message is used to * contain the translated payload.//from www . ja va 2 s . co m * * @param obj * The telemetry artifact. * @param jsmSess * The JMS session. * @return a text message containing the translated payload. * * @see org.springframework.jms.support.converter.MessageConverter#toMessage(java.lang.Object, * javax.jms.Session) */ public Message toMessage(Object obj, Session jmsSess) throws JMSException, MessageConversionException { TextMessage m = jmsSess.createTextMessage(); GlobalInfo telemetry = (GlobalInfo) obj; m.setJMSCorrelationID(telemetry.getEntityId().toString()); m.setStringProperty(GlobalInfoFields.ReportingNode.name(), telemetry.getReportingNode()); if (telemetry.containsKey(ExecInfoFields.OperationName.name())) { m.setStringProperty(ExecInfoFields.OperationName.name(), (String) telemetry.get(ExecInfoFields.OperationName.name())); } if (telemetry.containsKey(ExecInfoFields.Status.name())) { m.setStringProperty(ExecInfoFields.Status.name(), telemetry.get(ExecInfoFields.Status.name()).toString()); } char[] body = m_translator.encode(telemetry); m.setText(new String(body)); return m; }
From source file:com.oneops.inductor.MessagePublisher.java
@Override protected boolean process(MessageHolder holder) { Map<String, String> event = holder.getMap(); try {//from www . java 2s .com TextMessage message = session.createTextMessage(event.get("body")); message.setJMSCorrelationID(event.get("correlationID")); for (Map.Entry<String, String> kv : event.entrySet()) { if (!kv.getKey().equals("body")) { message.setStringProperty(kv.getKey(), kv.getValue()); } } MessageProducer producer = regularProducer; if ("high".equals(event.get("priority"))) { producer = priorityProducer; logger.debug("using priority producer to publish message"); } producer.send(message); logger.debug("Published: " + message.toString()); return true; } catch (NullPointerException npe) { // happens when amq session is null logger.warn("caught NullPointerException - reconnecting to broker"); waitSome(); init(); return false; } catch (IllegalStateException e) { // this happens when connection is hosed - lets re-init logger.warn("caught IllegalStateException - reconnecting to broker"); init(); return false; } catch (JMSException e) { logger.error(e.getMessage()); logger.debug(e.getMessage(), e); return false; } }
From source file:org.apache.activemq.camel.JmsJdbcXARollbackTest.java
private void sendJMSMessageToKickOffRoute() throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://testXA"); factory.setWatchTopicAdvisories(false); Connection connection = factory.createConnection(); connection.start();/* w ww.j a v a 2s. c o m*/ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = session.createProducer(new ActiveMQQueue("scp_transacted")); TextMessage message = session.createTextMessage("Some Text, messageCount:" + messageCount++); message.setJMSCorrelationID("pleaseCorrelate"); producer.send(message); connection.close(); }
From source file:net.blogracy.services.SeedService.java
@Override public void onMessage(Message request) { try {// ww w . j a va 2 s .c o m String text = ((TextMessage) request).getText(); Logger.info("seed service:" + text + ";"); JSONObject entry = new JSONObject(text); try { File file = new File(entry.getString("file")); Torrent torrent = plugin.getTorrentManager().createFromDataFile(file, new URL("udp://tracker.openbittorrent.com:80")); torrent.setComplete(file.getParentFile()); String name = Base32.encode(torrent.getHash()); int index = file.getName().lastIndexOf('.'); if (0 < index && index <= file.getName().length() - 2) { name = name + file.getName().substring(index); } Download download = plugin.getDownloadManager().addDownload(torrent, null, // torrentFile, file.getParentFile()); if (download != null) download.renameDownload(name); entry.put("uri", torrent.getMagnetURI().toExternalForm()); if (request.getJMSReplyTo() != null) { TextMessage response = session.createTextMessage(); response.setText(entry.toString()); response.setJMSCorrelationID(request.getJMSCorrelationID()); producer.send(request.getJMSReplyTo(), response); } } catch (MalformedURLException e) { Logger.error("Malformed URL error: seed service " + text); } catch (TorrentException e) { Logger.error("Torrent error: seed service: " + text); e.printStackTrace(); } catch (DownloadException e) { Logger.error("Download error: seed service: " + text); e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } catch (JMSException e) { Logger.error("JMS error: seed service"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.apache.servicemix.jms.JmsProviderEndpointTest.java
public void testSoapProviderInOut() throws Exception { JmsComponent component = new JmsComponent(); JmsSoapProviderEndpoint endpoint = new JmsSoapProviderEndpoint(); endpoint.setService(new QName("uri:HelloWorld", "HelloService")); endpoint.setEndpoint("HelloPort"); endpoint.setConnectionFactory(connectionFactory); endpoint.setDestinationName("destination"); endpoint.setReplyDestinationName("reply"); endpoint.setWsdl(new ClassPathResource("org/apache/servicemix/jms/HelloWorld-RPC.wsdl")); component.setEndpoints(new JmsProviderEndpoint[] { endpoint }); container.activateComponent(component, "servicemix-jms"); Thread th = new Thread() { public void run() { try { final Message msg = jmsTemplate.receive("destination"); assertNotNull(msg);/*from w w w . j a v a 2s .c o m*/ final ByteArrayOutputStream baos = new ByteArrayOutputStream(); FileUtil.copyInputStream( new ClassPathResource("org/apache/servicemix/jms/HelloWorld-RPC-Output.xml") .getInputStream(), baos); jmsTemplate.send("reply", new MessageCreator() { public Message createMessage(Session session) throws JMSException { TextMessage rep = session.createTextMessage(baos.toString()); rep.setJMSCorrelationID(msg.getJMSCorrelationID() != null ? msg.getJMSCorrelationID() : msg.getJMSMessageID()); return rep; } }); } catch (Exception e) { e.printStackTrace(); } } }; th.start(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); FileUtil.copyInputStream( new ClassPathResource("org/apache/servicemix/jms/HelloWorld-RPC-Input-Hello.xml").getInputStream(), baos); InOut me = client.createInOutExchange(); me.getInMessage().setContent(new StringSource(baos.toString())); me.setOperation(new QName("uri:HelloWorld", "Hello")); me.setService(new QName("uri:HelloWorld", "HelloService")); client.sendSync(me); assertEquals(ExchangeStatus.ACTIVE, me.getStatus()); assertNotNull(me.getOutMessage()); assertNotNull(me.getOutMessage().getContent()); System.err.println(new SourceTransformer().contentToString(me.getOutMessage())); client.done(me); }
From source file:de.taimos.dvalin.interconnect.core.spring.DaemonMessageSender.java
private void sendIVO(final String correlationID, final Destination replyTo, final InterconnectObject ico, final boolean secure) throws Exception { final String json = InterconnectMapper.toJson(ico); this.logger.debug("TextMessage send: " + json); this.template.send(replyTo, new MessageCreator() { @Override// www. j a va2s.c o m public Message createMessage(final Session session) throws JMSException { final TextMessage textMessage = session.createTextMessage(); textMessage.setStringProperty(InterconnectConnector.HEADER_ICO_CLASS, ico.getClass().getName()); textMessage.setJMSCorrelationID(correlationID); textMessage.setText(json); if (secure) { try { MessageConnector.secureMessage(textMessage); } catch (CryptoException e) { throw new JMSException(e.getMessage()); } } return textMessage; } }); }
From source file:com.oneops.controller.jms.InductorPublisher.java
/** * Publish message.// w ww . j ava2 s . c o m * * @param waitTaskName the wait task name * @param woType the wo type * @throws JMSException the jMS exception */ public void publishMessage(String processId, String execId, CmsWorkOrderSimpleBase wo, String waitTaskName, String woType) throws JMSException { SimpleDateFormat format = new SimpleDateFormat(CmsConstants.SEARCH_TS_PATTERN); wo.getSearchTags().put(CmsConstants.REQUEST_ENQUE_TS, format.format(new Date())); //guarantee non empty-value for searchMap if (version != null && StringUtils.isNotBlank(version.getGitVersion())) { wo.getSearchTags().put(CONTROLLLER_VERSION_SEARCH_TAG, version.getGitVersion()); } else { wo.getSearchTags().put(CONTROLLLER_VERSION_SEARCH_TAG, DEFAULT_VERSION); } TextMessage message = session.createTextMessage(gson.toJson(wo)); String corelationId = processId + "!" + execId + "!" + waitTaskName + "!" + getCtxtId(wo); message.setJMSCorrelationID(corelationId); message.setStringProperty("task_id", corelationId); message.setStringProperty("type", woType); String queueName = getQueue(wo); bindingQueusMap.computeIfAbsent(queueName, k -> { try { return newMessageProducer(k); } catch (JMSException e) { throw new RuntimeException(e); } }).send(message); if (logger.isDebugEnabled()) { logger.debug("Published: " + message.getText()); } logger.info("Posted message with id " + corelationId + " to q: " + queueName); }