List of usage examples for javax.jms Message setStringProperty
void setStringProperty(String name, String value) throws JMSException;
From source file:net.timewalker.ffmq4.admin.RemoteAdministrationThread.java
@Override public void run() { log.info("Starting remote administration thread ..."); try {//from w w w.ja va 2 s. c o m LocalQueue inputQueue = engine.getLocalQueue(FFMQConstants.ADM_REQUEST_QUEUE); LocalQueue outputQueue = engine.getLocalQueue(FFMQConstants.ADM_REPLY_QUEUE); conn = new LocalQueueConnection(engine, null, null); session = conn.createQueueSession(true, Session.SESSION_TRANSACTED); receiver = session.createReceiver(inputQueue); sender = session.createSender(outputQueue); conn.start(); // Flush input queue on startup inputQueue.purge(null); outputQueue.purge(null); // Enter listening loop notifyStartup(); while (!stopRequired) { Message message = receiver.receive(); if (message == null) break; // Interrupted log.debug("Received message " + message); try { // Process the command String errorMsg = process(message); // Build response message Message response = session.createMessage(); response.setJMSCorrelationID(message.getJMSMessageID()); if (errorMsg != null) response.setStringProperty(FFMQAdminConstants.ADM_HEADER_ERRMSG, errorMsg); sender.send(response, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE); } catch (JMSException e) { log.error("Cannot process admin command", e); } finally { session.commit(); } } log.debug("Remote administration thread has stopped"); } catch (Throwable e) { log.fatal("Administration thread failed", e); notifyStartup(); } finally { try { if (sender != null) sender.close(); } catch (JMSException e) { ErrorTools.log(e, log); } try { if (receiver != null) receiver.close(); } catch (JMSException e) { ErrorTools.log(e, log); } try { if (session != null) session.close(); } catch (JMSException e) { ErrorTools.log(e, log); } try { if (conn != null) conn.close(); } catch (JMSException e) { ErrorTools.log(e, log); } } }
From source file:org.sdnmq.jms.PacketHandler.java
/** * Adds message properties according to IPv4 header fields. * // ww w .j a va2 s . co m * @param ipv4 the IPv4 packet * @param msg the message whose properties are set */ private void ipv4ToProperties(IPv4 ipv4, Message msg) { try { msg.setStringProperty(MessageFilterAttributes.Keys.NW_SRC.toFilterName(), Netutil.ipv4ToStr(ipv4.getSourceAddress())); msg.setStringProperty(MessageFilterAttributes.Keys.NW_SRC_BINARY.toFilterName(), Netutil.ipv4ToBinaryStr(ipv4.getSourceAddress())); } catch (JMSException e) { log.error(e.getMessage()); } try { msg.setStringProperty(MessageFilterAttributes.Keys.NW_DST.toFilterName(), Netutil.ipv4ToStr(ipv4.getDestinationAddress())); msg.setStringProperty(MessageFilterAttributes.Keys.NW_DST_BINARY.toFilterName(), Netutil.ipv4ToBinaryStr(ipv4.getDestinationAddress())); } catch (JMSException e) { log.error(e.getMessage()); } try { msg.setShortProperty(MessageFilterAttributes.Keys.NW_PROTOCOL.toFilterName(), (short) ipv4.getProtocol()); } catch (JMSException e) { log.error(e.getMessage()); } }
From source file:org.jwebsocket.jms.endpoint.JMSEndPointSender.java
/** * * @param aTargetId// w w w . j a v a 2s . c o m * @param aCorrelationID * @param aText * @param aResponseListener * @param aTimeout */ public synchronized void sendText(String aTargetId, final String aCorrelationID, final String aText, IJMSResponseListener aResponseListener, long aTimeout) { Message lMsg; try { lMsg = mSession.createTextMessage(aText); if (null != aCorrelationID) { lMsg.setJMSCorrelationID(aCorrelationID); } lMsg.setStringProperty("targetId", aTargetId); lMsg.setStringProperty("sourceId", mEndPointId); if (mLog.isDebugEnabled()) { StringBuilder lPropStr = new StringBuilder(); Enumeration lPropNames = lMsg.getPropertyNames(); while (lPropNames.hasMoreElements()) { String lPropName = (String) lPropNames.nextElement(); Object lValue = lMsg.getObjectProperty(lPropName); lPropStr.append(lPropName).append("=").append(lValue); if (lPropNames.hasMoreElements()) { lPropStr.append(", "); } } mLog.debug("Sending text to '" + aTargetId + "': " + (JMSLogging.isFullTextLogging() ? aText : "[content suppressed, length: " + aText.length() + " bytes]") + ", props: " + lPropStr + "..."); } // processing callbacks if (null != aResponseListener) { Assert.notNull(aCorrelationID, "The 'correlationID' argument cannot be null!"); Assert.isTrue(aTimeout > 0, "Invalid 'timeout' argument. Expecting 'timeout' > 0"); // setting the expiration time lMsg.setJMSExpiration(aTimeout); // saving the callback mResponseListeners.put(aCorrelationID, aResponseListener); // schedule the timer task Tools.getTimer().schedule(new JWSTimerTask() { @Override public void runTask() { Thread lThread = new Thread() { @Override public void run() { IJMSResponseListener lListener = mResponseListeners.remove(aCorrelationID); if (null != lListener) { lListener.onTimeout(); } } }; lThread.setName("JMSEndPointSender Timeout Thread"); Tools.getThreadPool().submit(lThread); } }, aTimeout); } mProducer.send(lMsg); } catch (JMSException lEx) { mLog.error(lEx.getClass().getSimpleName() + " sending message: " + lEx.getMessage() + " " + ExceptionUtils.getStackTrace(lEx)); } }
From source file:com.fusesource.forge.jmstest.tests.AsyncProducer.java
public void run() { try {/*ww w .j a v a 2s . c o m*/ Connection conn = getConnection(); Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); if (isExpectReply()) { Destination replyTo = getDestinationProvider().getDestination(session, getReplyDestination()); MessageConsumer consumer = session.createConsumer(replyTo); consumer.setMessageListener(this); } Destination dest = getDestinationProvider().getDestination(session, getDestinationName()); MessageProducer producer = session.createProducer(dest); producer.setDeliveryMode(getDeliveryMode().getCode()); getConnection().start(); LOG.info(">>Starting Message send loop"); while (!done.get()) { try { locallySent++; Destination replyDest = null; Message msg = getMessageFactory().createMessage(session); if (getMsgGroup() != null) { LOG.debug("Setting message group to : " + getMsgGroup()); msg.setStringProperty("JMSXGroupID", getMsgGroup()); if (getMessagesToSend() > 0) { if (locallySent == getMessagesToSend()) { LOG.debug("Closing message group: " + getMsgGroup()); msg.setIntProperty("JMSXGroupSeq", 0); } } } msg.setLongProperty("MsgNr", locallySent); if (isExpectReply()) { corrId = getReplyDestination() + "Seq-" + locallySent; msg.setStringProperty("JMSCorrelationID", corrId); replyDest = getDestinationProvider().getDestination(session, getReplyDestination()); msg.setJMSReplyTo(replyDest); receivedResponse = false; } long sendTime = System.currentTimeMillis(); producer.send(msg, deliveryMode.getCode(), 4, ttl); if (sent != null) { sent.incrementAndGet(); } done.set((getMessagesToSend() > 0) && ((locallySent) == getMessagesToSend())); if (isExpectReply()) { try { LOG.debug("Waiting for response ..."); synchronized (corrId) { try { if (getReplyTimeOut() > 0) { corrId.wait(getReplyTimeOut()); } else { corrId.wait(); } } catch (InterruptedException ie) { } if (receivedResponse) { long duration = System.currentTimeMillis() - sendTime; LOG.debug("Got response from peer in " + duration + " ms"); } else { LOG.error("Response not received within time frame..."); if (timeOuts != null) { timeOuts.incrementAndGet(); } } } } catch (Exception e) { if (exceptions != null) { exceptions.incrementAndGet(); } } } if (sleep > 0L) { try { Thread.sleep(sleep); } catch (InterruptedException ie) { } } } catch (JMSException e) { if (exceptions != null) { exceptions.incrementAndGet(); } } } } catch (Exception e) { } finally { try { closeConnection(); } catch (Throwable e) { } } LOG.info(">>MessageSender done...(" + sent + ")"); }
From source file:org.apache.activemq.web.AjaxTest.java
@Test(timeout = 15 * 1000) public void testAjaxClientMayUseSelectors() throws Exception { LOG.debug("*** testAjaxClientMayUseSelectors ***"); int port = getPort(); // send 2 messages to the same queue w/ different 'filter' values. Message msg = session.createTextMessage("test one"); msg.setStringProperty("filter", "one"); producer.send(msg);/*from w w w. j a v a 2s .co m*/ msg = session.createTextMessage("test two"); msg.setStringProperty("filter", "two"); producer.send(msg); HttpClient httpClient = new HttpClient(); httpClient.start(); // client subscribes to queue LOG.debug("SENDING LISTEN"); String sessionId = subscribe(httpClient, port, "destination=queue://test&type=listen&message=handler", "filter='two'", null); // client 1 polls for messages LOG.debug("SENDING POLL"); final StringBuffer buf = new StringBuffer(); final CountDownLatch latch = asyncRequest(httpClient, "http://localhost:" + port + "/amq?timeout=5000", buf, sessionId); latch.await(); LOG.debug(buf.toString()); String expected = "<response id='handler' destination='queue://test' >test two</response>"; assertContains(expected, buf.toString()); httpClient.stop(); }
From source file:org.apache.axis2.transport.jms.JMSSender.java
private void setProperty(Message message, MessageContext msgCtx, String key) { String value = getProperty(msgCtx, key); if (value != null) { try {//from w ww . ja v a2s .co m message.setStringProperty(key, value); } catch (JMSException e) { log.warn("Couldn't set message property : " + key + " = " + value, e); } } }
From source file:com.amalto.core.server.routing.DefaultRoutingEngine.java
private void sendMessage(final ItemPOJOPK itemPOJOPK, ArrayList<RoutingRulePOJO> routingRulesThatMatched) { // Sort execution order and send JMS message Collections.sort(routingRulesThatMatched); final String[] ruleNames = new String[routingRulesThatMatched.size()]; int i = 0;/*from w w w .java2s .c o m*/ for (RoutingRulePOJO rulePOJO : routingRulesThatMatched) { ruleNames[i] = rulePOJO.getPK().getUniqueId(); i++; } jmsTemplate.send(new MessageCreator() { @Override public Message createMessage(Session session) throws JMSException { Message message = session.createMessage(); setRulesList(message, ruleNames); message.setStringProperty(JMS_CONTAINER_PROPERTY, itemPOJOPK.getDataClusterPOJOPK().getUniqueId()); message.setStringProperty(JMS_TYPE_PROPERTY, itemPOJOPK.getConceptName()); message.setStringProperty(JMS_PK_PROPERTY, Util.joinStrings(itemPOJOPK.getIds(), ".")); message.setLongProperty(JMS_SCHEDULED, System.currentTimeMillis()); return message; } }); }
From source file:org.jbpm.jms.JmsConnectorService.java
protected void populateMessage(Message message, Job job) throws JMSException { message.setLongProperty("jobId", job.getId()); if (job instanceof Timer) { Timer timer = (Timer) job; if (log.isDebugEnabled()) { log.debug("scheduling " + timer + " to execute at " + timer.getDueDate()); }/*from w ww. j a v a 2 s .c o m*/ message.setLongProperty(SCHEDULED_DELIVERY_PROP, timer.getDueDate().getTime()); // raise timer priority message.setJMSPriority(9); } if (job.isExclusive()) { message.setStringProperty(GROUP_ID_PROP, GROUP_PREFIX + job.getProcessInstance().getId()); } }
From source file:com.adaptris.core.jms.MetadataHandler.java
/** * <p>// ww w.j a v a 2s .c om * Moves metadata from an <code>AdaptrisMessage</code> to a <code>javax.jms.Message</code> if <code>moveMetadata</code> is * <code>true</code>. * </p> * * @param in the <code>AdaptrisMessage</code> to move metadata from * @param out the JMS <code>Message</code> to move metadata to * @return the JMS <code>Message</code> with metadata added * @throws JMSException */ public final Message moveMetadata(AdaptrisMessage in, Message out) throws JMSException { MetadataCollection metadataCollection = context.metadataFilter().filter(in); if (context.metadataConverters().size() == 0) { new StringMetadataConverter().moveMetadata(metadataCollection, out); } else { for (MetadataConverter converter : context.metadataConverters()) { converter.moveMetadata(metadataCollection, out); } } out.setStringProperty(MESSAGE_UNIQUE_ID_KEY, in.getUniqueId()); if (context.moveJmsHeaders()) { moveJmsHeaders(in, out); } return out; }
From source file:org.apache.synapse.message.store.impl.jms.JmsProducer.java
private void setJmsMessageProperties(Message message, MessageContext synCtx) { Set<String> properties = synCtx.getPropertyKeySet(); for (String prop : properties) { if (prop.startsWith(JMS_MSG_P)) { Object value = synCtx.getProperty(prop); String key = prop.substring(JMS_MSG_P.length()); try { if (value instanceof String) { message.setStringProperty(key, (String) value); } else if (value instanceof Long) { message.setLongProperty(key, (Long) value); } else if (value instanceof Integer) { message.setIntProperty(key, (Integer) value); } else if (value instanceof Boolean) { message.setBooleanProperty(key, (Boolean) value); } else if (value instanceof Double) { message.setDoubleProperty(key, (Double) value); } else if (value instanceof Float) { message.setFloatProperty(key, (Float) value); } else if (value instanceof Short) { message.setShortProperty(key, (Short) value); }//from w w w . j a v a 2 s. com } catch (JMSException e) { if (logger.isDebugEnabled()) { logger.debug("Could not save Message property: " + e.getLocalizedMessage()); } } } } }