List of usage examples for javax.jms TextMessage setIntProperty
void setIntProperty(String name, int value) throws JMSException;
From source file:org.apache.uima.examples.as.GetMetaRequest.java
/** * retrieve meta information for a UIMA-AS Service attached to a broker * It uses the port 1099 as the JMX port on the broker, unless overridden * by defining the system property activemq.broker.jmx.port with a value of another port number * It uses the default JMX ActiveMQ Domain "org.apache.activemq", unless overridden * by defining the system property activemq.broker.jmx.domain with a value of the domain to use * This normally never needs to be done unless multiple brokers are run on the same node * as is sometimes done for unit tests. * @param args - brokerUri serviceName [-verbose] *///from w w w. jav a 2 s.co m public static void main(String[] args) { if (args.length < 2) { System.err.println("Need arguments: brokerURI serviceName [-verbose]"); System.exit(1); } String brokerURI = args[0]; String queueName = args[1]; boolean printReply = false; if (args.length > 2) { if (args[2].equalsIgnoreCase("-verbose")) { printReply = true; } else { System.err.println("Unknown argument: " + args[2]); System.exit(1); } } final Connection connection; Session producerSession = null; Queue producerQueue = null; MessageProducer producer; MessageConsumer consumer; Session consumerSession = null; TemporaryQueue consumerDestination = null; long startTime = 0; // Check if JMX server port number was specified jmxPort = System.getProperty("activemq.broker.jmx.port"); if (jmxPort == null || jmxPort.trim().length() == 0) { jmxPort = "1099"; // default } try { // First create connection to a broker ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerURI); connection = factory.createConnection(); connection.start(); Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { public void run() { try { if (connection != null) { connection.close(); } if (jmxc != null) { jmxc.close(); } } catch (Exception ex) { } } })); URI target = new URI(brokerURI); String brokerHost = target.getHost(); attachToRemoteBrokerJMXServer(brokerURI); if (isQueueAvailable(queueName) == QueueState.exists) { System.out.println("Queue " + queueName + " found on " + brokerURI); System.out.println("Sending getMeta..."); } else if (isQueueAvailable(queueName) == QueueState.existsnot) { System.err.println("Queue " + queueName + " does not exist on " + brokerURI); System.exit(1); } else { System.out.println("Cannot see queues on JMX port " + brokerHost + ":" + jmxPort); System.out.println("Sending getMeta anyway..."); } producerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); producerQueue = producerSession.createQueue(queueName); producer = producerSession.createProducer(producerQueue); consumerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); consumerDestination = consumerSession.createTemporaryQueue(); // ----------------------------------------------------------------------------- // Create message consumer. The consumer uses a selector to filter out messages other // then GetMeta replies. Currently UIMA AS service returns two messages for each request: // ServiceInfo message and GetMeta message. The ServiceInfo message is returned by the // service immediately upon receiving a message from a client. This serves dual purpose, // 1) to make sure the client reply destination exists // 2) informs the client which service is processing its request // ----------------------------------------------------------------------------- consumer = consumerSession.createConsumer(consumerDestination, "Command=2001"); TextMessage msg = producerSession.createTextMessage(); msg.setStringProperty(AsynchAEMessage.MessageFrom, consumerDestination.getQueueName()); msg.setStringProperty(UIMAMessage.ServerURI, brokerURI); msg.setIntProperty(AsynchAEMessage.MessageType, AsynchAEMessage.Request); msg.setIntProperty(AsynchAEMessage.Command, AsynchAEMessage.GetMeta); msg.setJMSReplyTo(consumerDestination); msg.setText(""); producer.send(msg); startTime = System.nanoTime(); System.out.println("Sent getMeta request to " + queueName + " at " + brokerURI); System.out.println("Waiting for getMeta reply..."); ActiveMQTextMessage reply = (ActiveMQTextMessage) consumer.receive(); long waitTime = (System.nanoTime() - startTime) / 1000000; System.out.println( "Reply from " + reply.getStringProperty("ServerIP") + " received in " + waitTime + " ms"); if (printReply) { System.out.println("Reply MessageText: " + reply.getText()); } } catch (Exception e) { System.err.println(e.toString()); } System.exit(0); }
From source file:net.homecredit.book.jms.JmsMessageProducer.java
/** * Generates JMS messages//from w ww . j ava 2 s . c o m */ @PostConstruct public void generateMessages() throws JMSException { for (int i = 0; i < messageCount; i++) { final int index = i; final String text = "Message number is " + i + "."; template.send(new MessageCreator() { public Message createMessage(Session session) throws JMSException { TextMessage message = session.createTextMessage(text); message.setIntProperty(MESSAGE_COUNT, index); logger.info("Sending message: " + text); return message; } }); } }
From source file:org.usergrid.websocket.SimpleMessageProducer.java
public void sendMessages() throws JMSException { for (int i = 0; i < numberOfMessages; ++i) { final StringBuilder payload = new StringBuilder(); payload.append("Message [").append(i).append("] sent at: ").append(new Date()); final int j = i; jmsTemplate.send(new MessageCreator() { @Override//from ww w .ja va 2 s . c o m public Message createMessage(Session session) throws JMSException { TextMessage message = session.createTextMessage(payload.toString()); message.setIntProperty("messageCount", j); logger.info("Sending message number [" + j + "]"); return message; } }); } }
From source file:com.mirth.connect.connectors.jms.JmsReceiverTests.java
private void putMessagesInDestination(Destination destination, int numMessages) throws Exception { if (numMessages > 0) { MessageProducer producer = session.createProducer(destination); producer.setDeliveryMode(DeliveryMode.PERSISTENT); logger.debug("Putting " + numMessages + " messages into destination"); for (int i = 0; i < numMessages; i++) { TextMessage message = session.createTextMessage(TEST_HL7_MESSAGE); message.setIntProperty("messageNumber", i); producer.send(message);// w ww. j ava 2 s. co m } } }
From source file:org.hawkular.apm.server.jms.AbstractPublisherJMS.java
/** * This method publishes the supplied items. * * @param tenantId The tenant id// w ww . ja v a 2 s .c om * @param items The items * @param subscriber The optional subscriber name * @param retryCount The retry count * @param delay The delay * @throws Exception Failed to publish */ protected void doPublish(String tenantId, List<T> items, String subscriber, int retryCount, long delay) throws Exception { String data = mapper.writeValueAsString(items); TextMessage tm = session.createTextMessage(data); if (tenantId != null) { tm.setStringProperty("tenant", tenantId); } if (subscriber != null) { tm.setStringProperty("subscriber", subscriber); } tm.setIntProperty("retryCount", retryCount); if (delay > 0) { tm.setLongProperty("_AMQ_SCHED_DELIVERY", System.currentTimeMillis() + delay); } if (log.isLoggable(Level.FINEST)) { log.finest("Publish: " + tm); } producer.send(tm); }
From source file:com.bleum.canton.jms.scheduler.AbstractJMSScheduler.java
/** * Send JMS message. Can be override./* w w w. j a va 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:ca.uhn.hunit.iface.AbstractJmsInterfaceImpl.java
@Override protected TestMessage<T> internalSendMessage(final TestMessage<T> theMessage) throws TestFailureException { LogFactory.INSTANCE.get(this).info("Sending message (" + theMessage.getRawMessage().length() + " bytes)"); try {/*from w w w .j av a 2 s. c o m*/ MessageCreator mc = new MessageCreator() { @Override public javax.jms.Message createMessage(Session theSession) throws JMSException { TextMessage textMessage = theSession.createTextMessage(theMessage.getRawMessage()); for (int i = 0; i < myMessagePropertyTableModel.getRowCount(); i++) { if (java.lang.String.class.equals(myMessagePropertyTableModel.getArgType(i))) { textMessage.setStringProperty(myMessagePropertyTableModel.getName(i), (String) myMessagePropertyTableModel.getArg(i)); } else if (java.lang.Integer.class.equals(myMessagePropertyTableModel.getArgType(i))) { textMessage.setIntProperty(myMessagePropertyTableModel.getName(i), (Integer) myMessagePropertyTableModel.getArg(i)); } else if (int.class.equals(myMessagePropertyTableModel.getArgType(i))) { textMessage.setIntProperty(myMessagePropertyTableModel.getName(i), (Integer) myMessagePropertyTableModel.getArg(i)); } } return textMessage; } }; myJmsTemplate.send(myQueueName, mc); LogFactory.INSTANCE.get(this).info("Sent message"); } catch (JmsException e) { throw new InterfaceWontSendException(this, e.getMessage(), e); } return null; }
From source file:org.apache.activemq.JmsTopicSendSameMessageTest.java
public void testSendReceive() throws Exception { messages.clear();/*from ww w .ja v a2 s.c o m*/ TextMessage message = session.createTextMessage(); for (int i = 0; i < data.length; i++) { message.setText(data[i]); message.setStringProperty("stringProperty", data[i]); message.setIntProperty("intProperty", i); if (verbose) { LOG.info("About to send a message: " + message + " with text: " + data[i]); } producer.send(producerDestination, message); } assertMessagesAreReceived(); }
From source file:org.apache.activemq.store.jdbc.JmsTransactionCommitFailureTest.java
private void sendMessage(String queueName, int count, boolean transacted) throws JMSException { Connection con = connectionFactory.createConnection(); try {// www.ja va 2 s. c om Session session = con.createSession(transacted, transacted ? Session.SESSION_TRANSACTED : Session.AUTO_ACKNOWLEDGE); try { Queue destination = session.createQueue(queueName); MessageProducer producer = session.createProducer(destination); try { for (int i = 0; i < count; i++) { TextMessage message = session.createTextMessage(); message.setIntProperty("MessageId", messageCounter); message.setText("Message-" + messageCounter++); producer.send(message); } if (transacted) { session.commit(); } } finally { producer.close(); } } finally { session.close(); } } finally { con.close(); } }
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 w w .j a 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(); }