List of usage examples for javax.jms TextMessage setJMSReplyTo
void setJMSReplyTo(Destination replyTo) throws JMSException;
From source file:net.blogracy.controller.FileSharing.java
public String seed(File file) { String uri = null;// w w w . j a va 2 s. c om try { Destination tempDest = session.createTemporaryQueue(); MessageConsumer responseConsumer = session.createConsumer(tempDest); JSONObject requestObj = new JSONObject(); requestObj.put("file", file.getAbsolutePath()); TextMessage request = session.createTextMessage(); request.setText(requestObj.toString()); request.setJMSReplyTo(tempDest); producer.send(seedQueue, request); TextMessage response = (TextMessage) responseConsumer.receive(); String msgText = ((TextMessage) response).getText(); JSONObject responseObj = new JSONObject(msgText); uri = responseObj.getString("uri"); } catch (Exception e) { e.printStackTrace(); } return uri; }
From source file:com.mothsoft.alexis.engine.retrieval.DocumentRetrievalTaskImpl.java
private String requestParse(final Long documentId, final String content) { Connection connection = null; Session session = null;/*from w w w .j a v a2s .c om*/ MessageProducer producer = null; // set up JMS connection, session, consumer, producer try { connection = this.connectionFactory.createConnection(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); producer = session.createProducer(this.requestQueue); logger.info("Sending parse request, document ID: " + documentId); final TextMessage textMessage = session.createTextMessage(content); textMessage.setJMSReplyTo(this.responseQueue); textMessage.setLongProperty(DOCUMENT_ID, documentId); producer.send(textMessage); } catch (JMSException e) { throw new RuntimeException(e); } finally { try { if (producer != null) { producer.close(); } if (session != null) { session.close(); } if (connection != null) { connection.close(); } } catch (JMSException e) { throw new RuntimeException(e); } } return content; }
From source file:org.openengsb.ports.jms.JMSPortTest.java
private String sendWithTempQueue(final String msg) { String resultString = jmsTemplate.execute(new SessionCallback<String>() { @Override/* w ww. j ava 2s. c o m*/ public String doInJms(Session session) throws JMSException { Queue queue = session.createQueue("receive"); MessageProducer producer = session.createProducer(queue); TemporaryQueue tempQueue = session.createTemporaryQueue(); MessageConsumer consumer = session.createConsumer(tempQueue); TextMessage message = session.createTextMessage(msg); message.setJMSReplyTo(tempQueue); producer.send(message); TextMessage response = (TextMessage) consumer.receive(10000); assertThat( "server should set the value of the correltion ID to the value of the received message id", response.getJMSCorrelationID(), is(message.getJMSMessageID())); JmsUtils.closeMessageProducer(producer); JmsUtils.closeMessageConsumer(consumer); return response != null ? response.getText() : null; } }, true); return resultString; }
From source file:com.bleum.canton.jms.scheduler.AbstractJMSScheduler.java
/** * Send JMS message. Can be override.//from w w w . j a v a 2 s. c o m * * @param task */ protected void sendMessage(final JMSTask task) { if (jmsSender == null) { throw new RuntimeException("jmsSender is null."); } MessageCreator mc = new MessageCreator() { public Message createMessage(Session session) throws JMSException { TextMessage om = session.createTextMessage(); om.setText(formMessage(task)); om.setIntProperty("clientAck", clientAck); if (clientAck == JMSTaskConstant.CLIENT_ACKNOWLEDGE) { om.setLongProperty("taskId", task.getId()); om.setJMSReplyTo(replyQueue); } return om; } }; jmsSender.send(mc); }
From source file:nl.nn.adapterframework.extensions.tibco.SendTibcoMessage.java
public String doPipeWithTimeoutGuarded(Object input, IPipeLineSession session) throws PipeRunException { Connection connection = null; Session jSession = null;/*ww w. j av a 2 s.co m*/ MessageProducer msgProducer = null; Destination destination = null; String url_work; String authAlias_work; String userName_work; String password_work; String queueName_work; String messageProtocol_work; int replyTimeout_work; String soapAction_work; String result = null; ParameterValueList pvl = null; if (getParameterList() != null) { ParameterResolutionContext prc = new ParameterResolutionContext((String) input, session); try { pvl = prc.getValues(getParameterList()); } catch (ParameterException e) { throw new PipeRunException(this, getLogPrefix(session) + "exception on extracting parameters", e); } } url_work = getParameterValue(pvl, "url"); if (url_work == null) { url_work = getUrl(); } authAlias_work = getParameterValue(pvl, "authAlias"); if (authAlias_work == null) { authAlias_work = getAuthAlias(); } userName_work = getParameterValue(pvl, "userName"); if (userName_work == null) { userName_work = getUserName(); } password_work = getParameterValue(pvl, "password"); if (password_work == null) { password_work = getPassword(); } queueName_work = getParameterValue(pvl, "queueName"); if (queueName_work == null) { queueName_work = getQueueName(); } messageProtocol_work = getParameterValue(pvl, "messageProtocol"); if (messageProtocol_work == null) { messageProtocol_work = getMessageProtocol(); } String replyTimeout_work_str = getParameterValue(pvl, "replyTimeout"); if (replyTimeout_work_str == null) { replyTimeout_work = getReplyTimeout(); } else { replyTimeout_work = Integer.parseInt(replyTimeout_work_str); } soapAction_work = getParameterValue(pvl, "soapAction"); if (soapAction_work == null) soapAction_work = getSoapAction(); if (StringUtils.isEmpty(soapAction_work) && !StringUtils.isEmpty(queueName_work)) { String[] q = queueName_work.split("\\."); if (q.length > 0) { if (q[0].equalsIgnoreCase("P2P") && q.length >= 4) { soapAction_work = q[3]; } else if (q[0].equalsIgnoreCase("ESB") && q.length == 8) { soapAction_work = q[5] + "_" + q[6]; } else if (q[0].equalsIgnoreCase("ESB") && q.length > 8) { soapAction_work = q[6] + "_" + q[7]; } } } if (StringUtils.isEmpty(soapAction_work)) { log.debug(getLogPrefix(session) + "deriving default soapAction"); try { URL resource = ClassUtils.getResourceURL(this, "/xml/xsl/esb/soapAction.xsl"); TransformerPool tp = new TransformerPool(resource, true); soapAction_work = tp.transform(input.toString(), null); } catch (Exception e) { log.error(getLogPrefix(session) + "failed to execute soapAction.xsl"); } } if (messageProtocol_work == null) { throw new PipeRunException(this, getLogPrefix(session) + "messageProtocol must be set"); } if (!messageProtocol_work.equalsIgnoreCase(REQUEST_REPLY) && !messageProtocol_work.equalsIgnoreCase(FIRE_AND_FORGET)) { throw new PipeRunException(this, getLogPrefix(session) + "illegal value for messageProtocol [" + messageProtocol_work + "], must be '" + REQUEST_REPLY + "' or '" + FIRE_AND_FORGET + "'"); } CredentialFactory cf = new CredentialFactory(authAlias_work, userName_work, password_work); try { TibjmsAdmin admin; try { admin = TibcoUtils.getActiveServerAdmin(url_work, cf); } catch (TibjmsAdminException e) { log.debug(getLogPrefix(session) + "caught exception", e); admin = null; } if (admin != null) { QueueInfo queueInfo; try { queueInfo = admin.getQueue(queueName_work); } catch (Exception e) { throw new PipeRunException(this, getLogPrefix(session) + " exception on getting queue info", e); } if (queueInfo == null) { throw new PipeRunException(this, getLogPrefix(session) + " queue [" + queueName_work + "] does not exist"); } try { admin.close(); } catch (TibjmsAdminException e) { log.warn(getLogPrefix(session) + "exception on closing Tibjms Admin", e); } } ConnectionFactory factory = new com.tibco.tibjms.TibjmsConnectionFactory(url_work); connection = factory.createConnection(cf.getUsername(), cf.getPassword()); jSession = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE); destination = jSession.createQueue(queueName_work); msgProducer = jSession.createProducer(destination); TextMessage msg = jSession.createTextMessage(); msg.setText(input.toString()); Destination replyQueue = null; if (messageProtocol_work.equalsIgnoreCase(REQUEST_REPLY)) { replyQueue = jSession.createTemporaryQueue(); msg.setJMSReplyTo(replyQueue); msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT); msgProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); msgProducer.setTimeToLive(replyTimeout_work); } else { msg.setJMSDeliveryMode(DeliveryMode.PERSISTENT); msgProducer.setDeliveryMode(DeliveryMode.PERSISTENT); } if (StringUtils.isNotEmpty(soapAction_work)) { log.debug( getLogPrefix(session) + "setting [SoapAction] property to value [" + soapAction_work + "]"); msg.setStringProperty("SoapAction", soapAction_work); } msgProducer.send(msg); if (log.isDebugEnabled()) { log.debug(getLogPrefix(session) + "sent message [" + msg.getText() + "] " + "to [" + msgProducer.getDestination() + "] " + "msgID [" + msg.getJMSMessageID() + "] " + "correlationID [" + msg.getJMSCorrelationID() + "] " + "replyTo [" + msg.getJMSReplyTo() + "]"); } else { if (log.isInfoEnabled()) { log.info(getLogPrefix(session) + "sent message to [" + msgProducer.getDestination() + "] " + "msgID [" + msg.getJMSMessageID() + "] " + "correlationID [" + msg.getJMSCorrelationID() + "] " + "replyTo [" + msg.getJMSReplyTo() + "]"); } } if (messageProtocol_work.equalsIgnoreCase(REQUEST_REPLY)) { String replyCorrelationId = msg.getJMSMessageID(); MessageConsumer msgConsumer = jSession.createConsumer(replyQueue, "JMSCorrelationID='" + replyCorrelationId + "'"); log.debug(getLogPrefix(session) + "] start waiting for reply on [" + replyQueue + "] selector [" + replyCorrelationId + "] for [" + replyTimeout_work + "] ms"); try { connection.start(); Message rawReplyMsg = msgConsumer.receive(replyTimeout_work); if (rawReplyMsg == null) { throw new PipeRunException(this, getLogPrefix(session) + "did not receive reply on [" + replyQueue + "] replyCorrelationId [" + replyCorrelationId + "] within [" + replyTimeout_work + "] ms"); } TextMessage replyMsg = (TextMessage) rawReplyMsg; result = replyMsg.getText(); } finally { } } else { result = msg.getJMSMessageID(); } } catch (JMSException e) { throw new PipeRunException(this, getLogPrefix(session) + " exception on sending message to Tibco queue", e); } finally { if (connection != null) { try { connection.close(); } catch (JMSException e) { log.warn(getLogPrefix(session) + "exception on closing connection", e); } } } return result; }
From source file:org.openanzo.combus.bayeux.BridgeConnectionManager.java
/** * Marks a temporary topic for deletion. Before deleting the topic, it will be unregistered via the notification registration service. The topic will be * deleted once that operation completes. * // w w w. j a v a 2s . co m * @param topicToClose * the temporary topic to close. * @param username * the username of the user to which the temporary topic belongs * @param clientId * the clientId of the specific Bayeux connection to which the temporary topic applies. */ private void cleanupTemporaryTopic(TemporaryTopic topicToClose, MessageConsumer tempTopicConsumerToClose, String username, String clientId) { String correlationId = UUID.randomUUID().toString(); mapLock.lock(); try { topicsToDelete.put(correlationId, new ClientStateToClose(tempTopicConsumerToClose, topicToClose, System.currentTimeMillis(), username, clientId)); } finally { mapLock.unlock(); } log.debug(LogUtils.COMBUS_MARKER, "Sending unregister subscriber message for {}/{}", username, clientId); try { TextMessage tmsg = session.createTextMessage(); tmsg.setJMSCorrelationID(correlationId); tmsg.setJMSReplyTo(topicToClose); tmsg.setStringProperty(SerializationConstants.operation, INotificationRegistrationService.UNREGISTER_SUBSCRIBER); tmsg.setStringProperty("runAsUser", username); mp.send(destinations.get(COMBUS.NOTIFICATION_SERVICE_QUEUE), tmsg); } catch (JMSException e) { MDC.put(LogUtils.USER, username); log.warn(LogUtils.COMBUS_MARKER, "Error while sending real-time update subscription remove request for " + username + "/" + clientId, e); MDC.clear(); } }
From source file:org.apache.activemq.usecases.RequestReplyToTopicViaThreeNetworkHopsTest.java
public void testMessages(Session sess, MessageProducer req_prod, Destination resp_dest, int num_msg) throws Exception { MessageConsumer resp_cons;// w ww. ja va2 s . c o m TextMessage msg; MessageClient cons_client; int cur; int tot_expected; resp_cons = sess.createConsumer(resp_dest); cons_client = new MessageClient(resp_cons, num_msg); cons_client.start(); cur = 0; while ((cur < num_msg) && (!fatalTestError)) { msg = sess.createTextMessage("MSG AAAA " + cur); msg.setIntProperty("SEQ", 100 + cur); msg.setStringProperty("TEST", "TOPO"); msg.setJMSReplyTo(resp_dest); if (cur == (num_msg - 1)) msg.setBooleanProperty("end-of-response", true); sendWithRetryOnDeletedDest(req_prod, msg); LOG.debug("Sent:" + msg); cur++; } // // Give the consumer some time to receive the response. // cons_client.waitShutdown(5000); // // Now shutdown the consumer if it's still running. // if (cons_client.shutdown()) LOG.debug("Consumer client shutdown complete"); else LOG.debug("Consumer client shutdown incomplete!!!"); // // Check that the correct number of messages was received. // tot_expected = num_msg * (echoResponseFill + 1); if (cons_client.getNumMsgReceived() == tot_expected) { LOG.debug("Have " + tot_expected + " messages, as-expected"); } else { testError = true; if (cons_client.getNumMsgReceived() == 0) fatalTestError = true; LOG.error("Have " + cons_client.getNumMsgReceived() + " messages; expected " + tot_expected + " on destination " + resp_dest); } resp_cons.close(); }
From source file:org.openanzo.combus.bayeux.BridgeConnectionManager.java
/** * Send a JMS message on behalf of the given client to a specific destination. The destination is a string that names an abstract queue such as that in * Constants.NOTIFICATION_SERVICE_QUEUE, etc. * // ww w. j a va 2 s . c om * @param clientId * @param destination * @param messageProperties * @param msgBody * @return returns whether or not this message was published to a topic * @throws JMSException * @throws AnzoException */ protected boolean sendClientMessage(String clientId, AnzoPrincipal principal, String destination, Map<?, ?> messageProperties, String msgBody, IOperationContext opContext) throws JMSException, AnzoException { //long destinationProfiler = profiler.start("Resolving destination."); Destination dest = destinations.get(destination); //profiler.stop(destinationProfiler); if (dest == null && destination.startsWith("services/")) { dest = session.createQueue(destination); destinations.put(destination, dest); } if (dest == null) { // we probably have a statement channel //long nullDestProfiler = profiler.start("Sending client message with null destination."); if (destination == null || !destination.startsWith(NAMESPACES.STREAM_TOPIC_PREFIX)) { //profiler.stop(nullDestProfiler); throw new AnzoException(ExceptionConstants.COMBUS.INVALID_TOPIC, destination); } // first we have to get the named graph uri out of the statement channel topic. String uri = UriGenerator.stripEncapsulatedString(NAMESPACES.STREAM_TOPIC_PREFIX, destination); URI graphUri = Constants.valueFactory.createURI(uri); if (!userHasGraphAddAccess(graphUri, principal, opContext)) { //profiler.stop(nullDestProfiler); throw new AnzoException(ExceptionConstants.COMBUS.NOT_AUTHORIZED_FOR_TOPIC, opContext.getOperationPrincipal().getUserURI().toString(), destination); } Topic topic = session.createTopic(destination); TextMessage tmsg = session.createTextMessage(); for (Map.Entry<?, ?> prop : messageProperties.entrySet()) { tmsg.setStringProperty(prop.getKey().toString(), prop.getValue().toString()); } tmsg.setText(msgBody); mp.send(topic, tmsg); //profiler.stop(nullDestProfiler); return true; } else { TemporaryTopic tempTopicForReply; //long = clientStateProfiler = profiler.start("Obtaining Bayeux client state."); mapLock.lock(); try { ClientState state = clientIdToClientState.get(clientId); if (state == null) { throw new AnzoException(ExceptionConstants.CLIENT.CLIENT_NOT_CONNECTED); } tempTopicForReply = state.topic; } finally { mapLock.unlock(); //profiler.stop(clientStateProfiler); } //long prepareJmsProfiler = profiler.start("Preparing JMS Message."); TextMessage tmsg = session.createTextMessage(); int priority = 4; for (Map.Entry<?, ?> prop : messageProperties.entrySet()) { if (JMS_MSG_PROPERTY_CORRELATION_ID.equals(prop.getKey())) { tmsg.setJMSCorrelationID(prop.getValue().toString()); } if (JMS_MSG_PROPERTY_PRIORITY.equals(prop.getKey())) { priority = Integer.parseInt(prop.getValue().toString()); } else { tmsg.setStringProperty(prop.getKey().toString(), prop.getValue().toString()); } } tmsg.setJMSPriority(priority); tmsg.setJMSReplyTo(tempTopicForReply); tmsg.setText(msgBody); String username = principal.getName(); tmsg.setStringProperty("runAsUser", username); //profiler.stop(prepareJmsProfiler); long sendJmsProfiler = profiler.start("Sending JMS Message"); mp.setPriority(priority); mp.send(dest, tmsg); profiler.stop(sendJmsProfiler); return false; } }