List of usage examples for javax.jms Message setStringProperty
void setStringProperty(String name, String value) throws JMSException;
From source file:org.apache.activemq.usecases.DurableSubscriberWithNetworkRestartTest.java
public void testSendOnAReceiveOnBWithTransportDisconnect() throws Exception { bridge(SPOKE, HUB);/* w ww.j a va2 s.c o m*/ startAllBrokers(); verifyDuplexBridgeMbean(); // Setup connection URI hubURI = brokers.get(HUB).broker.getTransportConnectors().get(0).getPublishableConnectURI(); URI spokeURI = brokers.get(SPOKE).broker.getTransportConnectors().get(0).getPublishableConnectURI(); ActiveMQConnectionFactory facHub = new ActiveMQConnectionFactory(hubURI); ActiveMQConnectionFactory facSpoke = new ActiveMQConnectionFactory(spokeURI); Connection conHub = facHub.createConnection(); Connection conSpoke = facSpoke.createConnection(); conHub.setClientID("clientHUB"); conSpoke.setClientID("clientSPOKE"); conHub.start(); conSpoke.start(); Session sesHub = conHub.createSession(false, Session.AUTO_ACKNOWLEDGE); Session sesSpoke = conSpoke.createSession(false, Session.AUTO_ACKNOWLEDGE); ActiveMQTopic topic = new ActiveMQTopic("TEST.FOO"); String consumerName = "consumerName"; // Setup consumers MessageConsumer remoteConsumer = sesHub.createDurableSubscriber(topic, consumerName); sleep(1000); remoteConsumer.close(); // Setup producer MessageProducer localProducer = sesSpoke.createProducer(topic); localProducer.setDeliveryMode(DeliveryMode.PERSISTENT); final String payloadString = new String(new byte[10 * 1024]); // Send messages for (int i = 0; i < MESSAGE_COUNT; i++) { Message test = sesSpoke.createTextMessage("test-" + i); test.setStringProperty("payload", payloadString); localProducer.send(test); } localProducer.close(); final String options = "?persistent=true&useJmx=true&deleteAllMessagesOnStartup=false"; for (int i = 0; i < 2; i++) { brokers.get(SPOKE).broker.stop(); sleep(1000); createBroker(new URI("broker:(tcp://localhost:61616)/" + SPOKE + options)); bridge(SPOKE, HUB); brokers.get(SPOKE).broker.start(); LOG.info("restarted spoke..:" + i); assertTrue("got mbeans on restart", Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { return countMbeans(brokers.get(HUB).broker, "networkBridge", 20000) == (dynamicOnly ? 1 : 2); } })); } }
From source file:org.jbpm.bpel.integration.jms.OutstandingRequest.java
public void sendReply(Map parts, QName faultName, Session jmsSession) throws JMSException { MessageProducer producer = null;//from w w w. ja v a 2 s .c o m try { producer = jmsSession.createProducer(replyDestination); /* * the given parts likely are an instance of PersistentMap which does not serialize nicely; * copy the parts to a transient Map implementation */ switch (parts.size()) { case 0: parts = Collections.EMPTY_MAP; break; case 1: { Map.Entry single = (Entry) parts.entrySet().iterator().next(); parts = Collections.singletonMap(single.getKey(), single.getValue()); break; } default: parts = new HashMap(parts); break; } Message responseMsg = jmsSession.createObjectMessage((Serializable) parts); responseMsg.setJMSCorrelationID(correlationID); // set the fault name, if any if (faultName != null) { responseMsg.setStringProperty(IntegrationConstants.FAULT_NAME_PROP, faultName.getLocalPart()); } // send the response producer.send(responseMsg); log.debug("sent response: " + RequestListener.messageToString(responseMsg)); } finally { if (producer != null) { try { producer.close(); } catch (JMSException e) { log.warn("could not close jms producer", e); } } } }
From source file:org.nebulaframework.grid.cluster.manager.services.jobs.remote.RemoteJobRequestMessageConverter.java
/** * Attaches a String property to the JMS Messages which * indicates the target cluster's Cluster ID. * /*from w w w .ja v a2 s.c o m*/ * @param object Object to be converted * @param JMS Session * * @return JMS Message */ @Override public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException { Message m = super.toMessage(object, session); if (object instanceof RemoteInvocation) { RemoteInvocation invocation = (RemoteInvocation) object; // If its a invocation of remoteJobRequest if (invocation.getMethodName().equals("remoteJobRequest")) { // Attach Target ClusterID m.setStringProperty("targetClusterId", parseClusterId((String) invocation.getArguments()[0])); } } return m; }
From source file:org.wso2.carbon.inbound.endpoint.protocol.jms.JMSReplySender.java
private void setProperty(Message message, org.apache.axis2.context.MessageContext msgCtx, String key) { String value = getProperty(msgCtx, key); if (value != null) { try {/*from w ww. java 2 s. c om*/ message.setStringProperty(key, value); } catch (JMSException e) { log.warn("Couldn't set message property : " + key + " = " + value, e); } } }
From source file:org.apache.openejb.activemq.JMS2AMQTest.java
@Test public void sendMessageToMdb() throws Exception { try (final JMSContext context = cf.createContext()) { Message message = context.createMessage(); message.setStringProperty("text", TEXT); context.createProducer().send(destination, message); assertTrue(Listener.sync());// w w w. j a v a2 s . c o m } catch (final JMSRuntimeException ex) { fail(ex.getMessage()); } }
From source file:org.esbtools.gateway.resubmit.service.JmsResubmitService.java
private ResubmitResponse enqueue(final ResubmitRequest resubmitRequest) { ResubmitResponse resubmitResponse = new ResubmitResponse(); try {//from w w w .j ava 2 s.com LOGGER.info("Sending message {}", resubmitRequest.getPayload()); jmsResubmitConfiguration.getBroker().send(resubmitRequest.getDestination(), new MessageCreator() { @Override public Message createMessage(Session session) throws JMSException { Message message = session.createTextMessage(resubmitRequest.getPayload()); if (MapUtils.isNotEmpty(resubmitRequest.getHeaders())) { for (Map.Entry<String, String> header : resubmitRequest.getHeaders().entrySet()) { LOGGER.info("Adding header key={}, value{}", header.getKey(), header.getValue()); message.setStringProperty(header.getKey(), header.getValue()); } } return message; } }); resubmitResponse.setStatus(GatewayResponse.Status.Success); } catch (RuntimeException e) { LOGGER.error("An error occurred when enqueuing the resubmit message: {}", resubmitRequest, e); throw new ResubmitFailedException(resubmitRequest); } LOGGER.info("{}", resubmitResponse); return resubmitResponse; }
From source file:tools.ProducerTool.java
@Override public void run() { Connection connection = null; Session session = null;/*from w w w. j av a2s . c om*/ try { connection = connectionFactory.createConnection(); if (clientId != null) { connection.setClientID(clientId); } session = connection.createSession(transacted, acknowledgeMode); Destination destination = null; if (jndiLookupDestinations) { destination = (Destination) context.lookup(destinationName); } else { if (useQueueDestinations) { if (useTemporaryDestinations) { destination = session.createTemporaryQueue(); } else { destination = session.createQueue(destinationName); } } else { if (useTemporaryDestinations) { destination = session.createTemporaryTopic(); } else { destination = session.createTopic(destinationName); } } } MessageProducer producer = session.createProducer(destination); if (durable) { producer.setDeliveryMode(DeliveryMode.PERSISTENT); } else { producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); } int numMessagesToSend = useFinalControlMessage ? numMessages - 1 : numMessages; for (int i = 0; i < numMessagesToSend; i++) { String messageText = "Message " + i + " at " + new Date(); if (bytesLength > -1) { byte[] messageTextBytes = messageText.getBytes(StandardCharsets.UTF_8); BytesMessage bytesMessage = session.createBytesMessage(); bytesMessage.writeBytes(messageTextBytes); if (messageTextBytes.length < bytesLength) { byte[] paddingBytes = new byte[bytesLength - messageTextBytes.length]; bytesMessage.writeBytes(paddingBytes); } if (messageGroupId != null) { bytesMessage.setStringProperty("JMSXGroupID", messageGroupId); } LOGGER.info("Sending bytes message"); producer.send(bytesMessage); } else { TextMessage textMessage = session.createTextMessage(messageText); if (messageGroupId != null) { textMessage.setStringProperty("JMSXGroupID", messageGroupId); } LOGGER.info("Sending text message: " + messageText); producer.send(textMessage); } if (perMessageSleepMS > 0) { Thread.sleep(perMessageSleepMS); } if (transacted) { if ((i + 1) % batchSize == 0) { session.commit(); } } } if (useFinalControlMessage) { Message message = session.createMessage(); if (messageGroupId != null) { message.setStringProperty("JMSXGroupID", messageGroupId); } LOGGER.info("Sending message"); producer.send(message); if (transacted) { session.commit(); } } producer.close(); } catch (Exception ex) { LOGGER.error("ProducerTool hit exception: " + ex.getMessage(), ex); } finally { if (session != null) { try { session.close(); } catch (JMSException e) { LOGGER.error("JMSException closing session", e); } } if (connection != null) { try { connection.close(); } catch (JMSException e) { LOGGER.error("JMSException closing session", e); } } } }
From source file:org.exist.messaging.JmsMessageSender.java
@Override public NodeImpl send(JmsMessagingConfiguration config, MessagingMetadata metadata, Item content) throws XPathException { // JMS specific checks config.validateContent();/*from www.j a v a2s . c o m*/ // Retrieve relevant values String initialContextFactory = config.getInitalContextProperty(Context.INITIAL_CONTEXT_FACTORY); String providerURL = config.getInitalContextProperty(Context.PROVIDER_URL); String connectionFactory = config.getConnectionFactory(); String destination = config.getDestination(); // TODO split up, use more exceptions, add better reporting try { Properties props = new Properties(); props.setProperty(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory); props.setProperty(Context.PROVIDER_URL, providerURL); javax.naming.Context context = new InitialContext(props); // Setup connection ConnectionFactory cf = (ConnectionFactory) context.lookup(connectionFactory); Connection connection = cf.createConnection(); // Lookup queue Destination dest = (Destination) context.lookup(destination); // Create session Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); // Create message producer MessageProducer producer = session.createProducer(dest); // Create message Message message = createMessage(session, content, metadata, xqcontext); // Write properties Map<String, String> kvs = metadata.getValueMap(); for (String key : kvs.keySet()) { message.setStringProperty(key, kvs.get(key)); } // Send message producer.send(message); // Close connection // TODO keep connection open for re-use, efficiency connection.close(); return createReport(message, xqcontext); } catch (Throwable ex) { LOG.error(ex); throw new XPathException(ex); } }
From source file:com.kinglcc.spring.jms.core.converter.Jackson2JmsMessageConverter.java
protected void setTypeIdOnMessage(Object object, Message message) throws JMSException { if (this.typeIdPropertyName != null) { String typeId = object.getClass().getCanonicalName(); message.setStringProperty(this.typeIdPropertyName, typeId); }/*from ww w .j a v a 2 s. c o m*/ }
From source file:org.sdnmq.jms.PacketHandler.java
/** * Adds message properties according to Ethernet header fields. * //from w ww .j a va 2 s.com * @param ethernet the Ethernet frame * @param msg the message object to which the information will be added */ private void ethernetToProperties(Ethernet ethernet, Message msg) { try { msg.setStringProperty(MessageFilterAttributes.Keys.DL_SRC.toFilterName(), Netutil.macToStr(ethernet.getSourceMACAddress())); } catch (JMSException e) { log.error(e.getMessage()); } try { msg.setStringProperty(MessageFilterAttributes.Keys.DL_DST.toFilterName(), Netutil.macToStr(ethernet.getDestinationMACAddress())); } catch (JMSException e) { log.error(e.getMessage()); } try { msg.setShortProperty(MessageFilterAttributes.Keys.DL_TYPE.toFilterName(), ethernet.getEtherType()); } catch (JMSException e) { log.error(e.getMessage()); } }