List of usage examples for javax.jms Message setLongProperty
void setLongProperty(String name, long value) throws JMSException;
From source file:com.fusesource.forge.jmstest.executor.BenchmarkProducer.java
public void sendMessage() { try {/*from ww w .j a v a 2 s . c om*/ Message msg = getMessageFactory().createMessage(getSession()); msg.setLongProperty("SendTime", System.currentTimeMillis()); messageProducer.send(msg, getContainer().getPartConfig().getDeliveryMode().getCode(), 4, 0); if (messageCounter != null) { messageCounter.increment(); msgNumber = messageCounter.getValue().longValue(); } else { msgNumber++; } msg.setLongProperty("MessageNumber", msgNumber); if (getContainer().getPartConfig().isTransacted()) { getSession().commit(); } } catch (Exception e) { // TODO attempt to reinitialise producer getBenchmarkStatus().setState(BenchmarkRunStatus.State.FAILED); log().warn("Failed to send message, entire benchmark will NOW FAIL!", e); } }
From source file:org.test.app.web.framework.backend.messaging.services.integration.impl.live.SampleRepositoryImpl.java
@Override public void fillHeader(final Message message, final AbstractIntegrationBean header) throws JMSException { message.setIntProperty("businessId", ((HeaderDTO) header).getSequenceId()); message.setLongProperty("businessDate", ((HeaderDTO) header).getDate().getTime()); }
From source file:springchat.service.MessagesServiceImpl.java
@Override @Secured({ "ROLE_CHATUSER" }) public void postMessage(final String message) { jmsTemplate.send("java:comp/env/NewTextMessageChannel", new MessageCreator() { public Message createMessage(Session session) throws JMSException { Message notification = session.createMessage(); Authentication auth = SecurityContextHolder.getContext().getAuthentication(); notification.setStringProperty("user", auth.getName()); notification.setLongProperty("date", new Date().getTime()); notification.setStringProperty("message", message); return notification; }/*from w w w . j a v a2 s .com*/ }); }
From source file:cherry.foundation.async.PropertyMessagePostProcessor.java
@Override public Message postProcessMessage(Message message) throws JMSException { for (Map.Entry<String, Object> entry : properties.entrySet()) { String name = entry.getKey(); Object v = entry.getValue(); if (v instanceof String) { message.setStringProperty(name, (String) v); } else if (v instanceof Integer) { message.setIntProperty(name, ((Integer) v).intValue()); } else if (v instanceof Long) { message.setLongProperty(name, ((Long) v).longValue()); } else if (v instanceof Short) { message.setShortProperty(name, ((Short) v).shortValue()); } else if (v instanceof Byte) { message.setByteProperty(name, ((Byte) v).byteValue()); } else if (v instanceof Boolean) { message.setBooleanProperty(name, ((Boolean) v).booleanValue()); } else if (v instanceof Double) { message.setDoubleProperty(name, ((Double) v).doubleValue()); } else if (v instanceof Float) { message.setFloatProperty(name, ((Float) v).floatValue()); } else {//w ww.j av a2 s.c om message.setObjectProperty(name, v); } } return message; }
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;/* w w w. j av a2 s .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:com.fusesource.forge.jmstest.tests.AsyncProducer.java
public void run() { try {/* w ww. j av a 2 s .co 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:hermes.impl.DefaultXMLHelper.java
public Message createMessage(MessageFactory hermes, XMLMessage message) throws JMSException, IOException, ClassNotFoundException, DecoderException { try {/*ww w .ja v a2 s. c o m*/ Message rval = hermes.createMessage(); if (message instanceof XMLTextMessage) { rval = hermes.createTextMessage(); XMLTextMessage textMessage = (XMLTextMessage) message; TextMessage textRval = (TextMessage) rval; if (BASE64_CODEC.equals(textMessage.getCodec())) { byte[] bytes = base64EncoderTL.get().decode(textMessage.getText().getBytes()); textRval.setText(new String(bytes, "ASCII")); } else { textRval.setText(textMessage.getText()); } } else if (message instanceof XMLMapMessage) { rval = hermes.createMapMessage(); XMLMapMessage mapMessage = (XMLMapMessage) message; MapMessage mapRval = (MapMessage) rval; for (Iterator iter = mapMessage.getBodyProperty().iterator(); iter.hasNext();) { final Property property = (Property) iter.next(); if (property.getValue() == null) { mapRval.setObject(property.getName(), null); } else if (property.getType().equals(String.class.getName())) { mapRval.setString(property.getName(), property.getValue()); } else if (property.getType().equals(Long.class.getName())) { mapRval.setLong(property.getName(), Long.parseLong(property.getValue())); } else if (property.getType().equals(Double.class.getName())) { mapRval.setDouble(property.getName(), Double.parseDouble(property.getValue())); } else if (property.getType().equals(Boolean.class.getName())) { mapRval.setBoolean(property.getName(), Boolean.getBoolean(property.getValue())); } else if (property.getType().equals(Character.class.getName())) { mapRval.setChar(property.getName(), property.getValue().charAt(0)); } else if (property.getType().equals(Short.class.getName())) { mapRval.setShort(property.getName(), Short.parseShort(property.getValue())); } else if (property.getType().equals(Integer.class.getName())) { mapRval.setInt(property.getName(), Integer.parseInt(property.getValue())); } } } else if (message instanceof XMLBytesMessage) { rval = hermes.createBytesMessage(); XMLBytesMessage bytesMessage = (XMLBytesMessage) message; BytesMessage bytesRval = (BytesMessage) rval; bytesRval.writeBytes(base64EncoderTL.get().decode(bytesMessage.getBytes().getBytes())); } else if (message instanceof XMLObjectMessage) { rval = hermes.createObjectMessage(); XMLObjectMessage objectMessage = (XMLObjectMessage) message; ObjectMessage objectRval = (ObjectMessage) rval; ByteArrayInputStream bistream = new ByteArrayInputStream( base64EncoderTL.get().decode(objectMessage.getObject().getBytes())); ObjectInputStream oistream = new ObjectInputStream(bistream); objectRval.setObject((Serializable) oistream.readObject()); } // // JMS Header properties try { rval.setJMSDeliveryMode(message.getJMSDeliveryMode()); } catch (JMSException ex) { log.error("unable to set JMSDeliveryMode to " + message.getJMSDeliveryMode() + ": " + ex.getMessage()); } try { rval.setJMSMessageID(message.getJMSMessageID()); } catch (JMSException ex) { log.error("unable to set JMSMessageID: " + ex.getMessage(), ex); } try { if (message.getJMSExpiration() != null) { rval.setJMSExpiration(message.getJMSExpiration()); } } catch (JMSException ex) { log.error("unable to set JMSExpiration: " + ex.getMessage(), ex); } try { if (message.getJMSPriority() != null) { rval.setJMSPriority(message.getJMSPriority()); } } catch (JMSException ex) { log.error("unable to set JMSPriority: " + ex.getMessage(), ex); } try { if (message.getJMSTimestamp() != null) { rval.setJMSTimestamp(message.getJMSTimestamp()); } } catch (JMSException ex) { log.error("unable to set JMSTimestamp:" + ex.getMessage(), ex); } if (message.getJMSCorrelationID() != null) { rval.setJMSCorrelationID(message.getJMSCorrelationID()); } if (message.getJMSReplyTo() != null && !message.getJMSReplyTo().equals("null")) { rval.setJMSReplyTo(hermes.getDestination(message.getJMSReplyTo(), Domain.getDomain(message.getJMSReplyToDomain()))); } if (message.getJMSType() != null) { rval.setJMSType(message.getJMSType()); } if (message.getJMSDestination() != null) { if (message.isFromQueue()) { rval.setJMSDestination(hermes.getDestination(message.getJMSDestination(), Domain.QUEUE)); } else { rval.setJMSDestination(hermes.getDestination(message.getJMSDestination(), Domain.TOPIC)); } } for (Iterator iter = message.getHeaderProperty().iterator(); iter.hasNext();) { Property property = (Property) iter.next(); if (property.getValue() == null) { rval.setObjectProperty(property.getName(), null); } else if (property.getType().equals(String.class.getName())) { rval.setStringProperty(property.getName(), StringEscapeUtils.unescapeXml(property.getValue())); } else if (property.getType().equals(Long.class.getName())) { rval.setLongProperty(property.getName(), Long.parseLong(property.getValue())); } else if (property.getType().equals(Double.class.getName())) { rval.setDoubleProperty(property.getName(), Double.parseDouble(property.getValue())); } else if (property.getType().equals(Boolean.class.getName())) { rval.setBooleanProperty(property.getName(), Boolean.parseBoolean(property.getValue())); } else if (property.getType().equals(Short.class.getName())) { rval.setShortProperty(property.getName(), Short.parseShort(property.getValue())); } else if (property.getType().equals(Integer.class.getName())) { rval.setIntProperty(property.getName(), Integer.parseInt(property.getValue())); } } return rval; } catch (NamingException e) { throw new HermesException(e); } }
From source file:nl.nn.adapterframework.jms.JmsSender.java
/** * sets the JMS message properties as descriped in the msgProperties arraylist * @param msg// w w w . j a v a 2 s . c om * @param msgProperties * @throws JMSException */ private void setProperties(Message msg, ParameterValueList msgProperties) throws JMSException { for (int i = 0; i < msgProperties.size(); i++) { ParameterValue property = msgProperties.getParameterValue(i); String type = property.getDefinition().getType(); String name = property.getDefinition().getName(); if (!isSoap() || !name.equals(getSoapHeaderParam())) { if (log.isDebugEnabled()) { log.debug(getLogPrefix() + "setting [" + type + "] property from param [" + name + "] to value [" + property.getValue() + "]"); } if ("boolean".equalsIgnoreCase(type)) msg.setBooleanProperty(name, property.asBooleanValue(false)); else if ("byte".equalsIgnoreCase(type)) msg.setByteProperty(name, property.asByteValue((byte) 0)); else if ("double".equalsIgnoreCase(type)) msg.setDoubleProperty(name, property.asDoubleValue(0)); else if ("float".equalsIgnoreCase(type)) msg.setFloatProperty(name, property.asFloatValue(0)); else if ("int".equalsIgnoreCase(type)) msg.setIntProperty(name, property.asIntegerValue(0)); else if ("long".equalsIgnoreCase(type)) msg.setLongProperty(name, property.asLongValue(0L)); else if ("short".equalsIgnoreCase(type)) msg.setShortProperty(name, property.asShortValue((short) 0)); else if ("string".equalsIgnoreCase(type)) msg.setStringProperty(name, property.asStringValue("")); else // if ("object".equalsIgnoreCase(type)) msg.setObjectProperty(name, property.getValue()); } } }
From source file:org.apache.axis2.transport.jms.JMSUtils.java
/** * Set transport headers from the axis message context, into the JMS message * * @param msgContext the axis message context * @param message the JMS Message/* w w w.j a v a 2s . c o m*/ * @throws JMSException on exception */ public static void setTransportHeaders(MessageContext msgContext, Message message) throws JMSException { Map<?, ?> headerMap = (Map<?, ?>) msgContext.getProperty(MessageContext.TRANSPORT_HEADERS); if (headerMap == null) { return; } for (Object headerName : headerMap.keySet()) { String name = (String) headerName; if (name.startsWith(JMSConstants.JMSX_PREFIX) && !(name.equals(JMSConstants.JMSX_GROUP_ID) || name.equals(JMSConstants.JMSX_GROUP_SEQ))) { continue; } if (JMSConstants.JMS_COORELATION_ID.equals(name)) { message.setJMSCorrelationID((String) headerMap.get(JMSConstants.JMS_COORELATION_ID)); } else if (JMSConstants.JMS_DELIVERY_MODE.equals(name)) { Object o = headerMap.get(JMSConstants.JMS_DELIVERY_MODE); if (o instanceof Integer) { message.setJMSDeliveryMode((Integer) o); } else if (o instanceof String) { try { message.setJMSDeliveryMode(Integer.parseInt((String) o)); } catch (NumberFormatException nfe) { log.warn("Invalid delivery mode ignored : " + o, nfe); } } else { log.warn("Invalid delivery mode ignored : " + o); } } else if (JMSConstants.JMS_EXPIRATION.equals(name)) { message.setJMSExpiration(Long.parseLong((String) headerMap.get(JMSConstants.JMS_EXPIRATION))); } else if (JMSConstants.JMS_MESSAGE_ID.equals(name)) { message.setJMSMessageID((String) headerMap.get(JMSConstants.JMS_MESSAGE_ID)); } else if (JMSConstants.JMS_PRIORITY.equals(name)) { message.setJMSPriority(Integer.parseInt((String) headerMap.get(JMSConstants.JMS_PRIORITY))); } else if (JMSConstants.JMS_TIMESTAMP.equals(name)) { message.setJMSTimestamp(Long.parseLong((String) headerMap.get(JMSConstants.JMS_TIMESTAMP))); } else if (JMSConstants.JMS_MESSAGE_TYPE.equals(name)) { message.setJMSType((String) headerMap.get(JMSConstants.JMS_MESSAGE_TYPE)); } else { Object value = headerMap.get(name); if (value instanceof String) { message.setStringProperty(name, (String) value); } else if (value instanceof Boolean) { message.setBooleanProperty(name, (Boolean) value); } else if (value instanceof Integer) { message.setIntProperty(name, (Integer) value); } else if (value instanceof Long) { message.setLongProperty(name, (Long) value); } else if (value instanceof Double) { message.setDoubleProperty(name, (Double) value); } else if (value instanceof Float) { message.setFloatProperty(name, (Float) value); } } } }