List of usage examples for javax.jms Session createProducer
MessageProducer createProducer(Destination destination) throws JMSException;
From source file:org.jbpm.bpel.tutorial.shipping.ShippingPT_Impl.java
protected void sendShippingMessage(String customerId) throws JMSException { // create a session Session jmsSession = jmsConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE); try {//w ww .j a va 2 s . c o m // create the message MapMessage message = jmsSession.createMapMessage(); message.setString("customerId", customerId); // send it! MessageProducer producer = jmsSession.createProducer(shippingDestination); producer.send(message); log.debug("Sent shipping message: customerId=" + customerId); } finally { jmsSession.close(); } }
From source file:org.apache.activemq.bugs.AMQ6133PersistJMSRedeliveryTest.java
private void sendMessages() throws Exception { Connection connection = createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination queue = session.createQueue(QUEUE_NAME); Destination retainQueue = session.createQueue(QUEUE_NAME + "-retain"); MessageProducer producer = session.createProducer(null); final byte[] payload = new byte[1000]; producer.setDeliveryMode(DeliveryMode.PERSISTENT); BytesMessage message = session.createBytesMessage(); message.writeBytes(payload);/*from w w w. j a va2s .c o m*/ // Build up a set of messages that will be redelivered and updated later. while (getLogFileCount() < 3) { producer.send(queue, message); } // Now create some space for files that are retained during the test. while (getLogFileCount() < 6) { producer.send(retainQueue, message); } connection.close(); }
From source file:com.datatorrent.lib.io.jms.JMSStringInputOperatorTest.java
private void produceMsg(int numMessages) throws Exception { // Create a ConnectionFactory ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost"); // Create a Connection Connection connection = connectionFactory.createConnection(); connection.start();// w w w . j a va2 s . co m // Create a Session Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); // Create the destination (Topic or Queue) Destination destination = session.createQueue("TEST.FOO"); // Create a MessageProducer from the Session to the Topic or Queue MessageProducer producer = session.createProducer(destination); producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); // Create a messages String text = "Hello world! From tester producer"; TextMessage message = session.createTextMessage(text); for (int i = 0; i < numMessages; i++) { producer.send(message); } // Clean up session.close(); connection.close(); }
From source file:org.apache.activemq.usecases.ConcurrentProducerDurableConsumerTest.java
private MessageProducer createMessageProducer(Session session, Destination destination) throws JMSException { MessageProducer producer = session.createProducer(destination); producer.setDeliveryMode(DeliveryMode.PERSISTENT); return producer; }
From source file:org.geoserver.wfs.notification.JMSEventHelper.java
private boolean fireNotification(String byteString, JMSInfo info) { Session session = null; for (int i = 0; i < 5 && !info.closed; ++i) { session = info.getSession();// www. j av a 2 s .c o m if (session == null) { continue; } try { MessageProducer producer = session.createProducer(null); Message message = session.createTextMessage(byteString); for (Destination d : info.destinations) { producer.send(d, message); } return true; } catch (Exception e) { recordFailure(e); info.invalidateSession(session); session = null; // Don't try to return the session continue; } finally { try { if (session != null) { info.returnSession(session); } } catch (Exception e) { // ignore } } } // Ran out of retries return false; }
From source file:org.dawnsci.commandserver.core.producer.AliveConsumer.java
protected void startNotifications() throws Exception { if (uri == null) throw new NullPointerException("Please set the URI before starting notifications!"); this.cbean = new ConsumerBean(); cbean.setStatus(ConsumerStatus.STARTING); cbean.setName(getName());// w ww.j a v a2 s .c o m cbean.setConsumerId(consumerId); cbean.setVersion(consumerVersion); cbean.setStartTime(System.currentTimeMillis()); try { cbean.setHostName(InetAddress.getLocalHost().getHostName()); } catch (UnknownHostException e) { // Not fatal but would be nice... e.printStackTrace(); } System.out.println("Running events on topic " + Constants.ALIVE_TOPIC + " to notify of '" + getName() + "' service being available."); final Thread aliveThread = new Thread(new Runnable() { public void run() { try { ConnectionFactory connectionFactory = ConnectionFactoryFacade.createConnectionFactory(uri); aliveConnection = connectionFactory.createConnection(); aliveConnection.start(); final Session session = aliveConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); final Topic topic = session.createTopic(Constants.ALIVE_TOPIC); final MessageProducer producer = session.createProducer(topic); final ObjectMapper mapper = new ObjectMapper(); // Here we are sending the message out to the topic while (isActive()) { try { Thread.sleep(Constants.NOTIFICATION_FREQUENCY); TextMessage temp = session.createTextMessage(mapper.writeValueAsString(cbean)); producer.send(temp, DeliveryMode.NON_PERSISTENT, 1, 5000); if (ConsumerStatus.STARTING.equals(cbean.getStatus())) { cbean.setStatus(ConsumerStatus.RUNNING); } } catch (InterruptedException ne) { break; } catch (Exception neOther) { neOther.printStackTrace(); } } } catch (Exception ne) { ne.printStackTrace(); setActive(false); } } }); aliveThread.setName("Alive Notification Topic"); aliveThread.setDaemon(true); aliveThread.setPriority(Thread.MIN_PRIORITY); aliveThread.start(); }
From source file:org.apache.servicemix.jbi.cluster.requestor.AbstractJmsRequestorPool.java
protected MessageProducer createProducer(Session session, Destination destination) throws JMSException { return session.createProducer(destination); }
From source file:org.apache.falcon.messaging.JMSMessageConsumerTest.java
public void sendMessages(String topic, WorkflowExecutionContext.Type type, boolean isFalconWF) throws JMSException, FalconException, IOException { ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(BROKER_URL); Connection connection = connectionFactory.createConnection(); connection.start();//from w ww .j av a 2 s. c o m Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Topic destination = session.createTopic(topic); javax.jms.MessageProducer producer = session.createProducer(destination); producer.setDeliveryMode(DeliveryMode.PERSISTENT); for (int i = 0; i < 5; i++) { Message message = null; switch (type) { case POST_PROCESSING: message = getMockFalconMessage(i, session); break; case WORKFLOW_JOB: message = getMockOozieMessage(i, session, isFalconWF); break; case COORDINATOR_ACTION: message = getMockOozieCoordMessage(i, session, isFalconWF); default: break; } Log.debug("Sending:" + message); producer.send(message); } }
From source file:org.springframework.integration.jms.ChannelPublishingJmsMessageListener.java
private void sendReply(javax.jms.Message replyMessage, Destination destination, Session session) throws JMSException { MessageProducer producer = session.createProducer(destination); try {//from ww w. j a va 2 s . c om if (this.explicitQosEnabledForReplies) { producer.send(replyMessage, this.replyDeliveryMode, this.replyPriority, this.replyTimeToLive); } else { producer.send(replyMessage); } } finally { JmsUtils.closeMessageProducer(producer); } }
From source file:org.openengsb.ports.jms.JMSPortTest.java
private String sendWithTempQueue(final String msg) { String resultString = jmsTemplate.execute(new SessionCallback<String>() { @Override//from www . j a v a2s . c om 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; }