List of usage examples for javax.jms MessageProducer close
void close() throws JMSException;
From source file:org.apache.activemq.usecases.DurableSubscriberWithNetworkRestartTest.java
public void testSendOnAReceiveOnBWithTransportDisconnect() throws Exception { bridge(SPOKE, HUB);//from www.ja va 2s .c om 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.apache.activemq.usecases.RequestReplyToTopicViaThreeNetworkHopsTest.java
/** * Test one destination between the given "producer broker" and "consumer broker" specified. *///from ww w . ja v a 2 s. c o m public void testOneDest(Connection conn, Session sess, Destination cons_dest, int num_msg) throws Exception { Destination prod_dest; MessageProducer msg_prod; // // Create the Producer to the echo request Queue // LOG.trace("Creating echo queue and producer"); prod_dest = sess.createQueue("echo"); msg_prod = sess.createProducer(prod_dest); // // Pass messages around. // testMessages(sess, msg_prod, cons_dest, num_msg); msg_prod.close(); }
From source file:org.apache.james.queue.jms.JMSMailQueue.java
protected static void closeProducer(MessageProducer producer) { if (producer != null) { try {/* ww w . j a v a 2 s.co m*/ producer.close(); } catch (JMSException e) { // Ignore. See JAMES-2509 } } }
From source file:org.apache.qpid.disttest.jms.ClientJmsDelegate.java
public void closeTestProducer(String producerName) { MessageProducer producer = _testProducers.get(producerName); if (producer != null) { try {/*from w w w . j av a2 s . c om*/ producer.close(); } catch (JMSException e) { throw new DistributedTestException("Failed to close producer: " + producerName, e); } } }
From source file:org.apache.synapse.transport.jms.JMSUtils.java
/** * Send the given message to the Destination using the given session * @param session the session to use to send * @param destination the Destination/* www .j a v a2s . com*/ * @param message the JMS Message * @throws AxisFault on error */ public static void sendMessageToJMSDestination(Session session, Destination destination, Message message) throws AxisFault { MessageProducer producer = null; try { if (log.isDebugEnabled()) { log.debug("Sending message to destination : " + destination); } if (destination instanceof Queue) { producer = ((QueueSession) session).createSender((Queue) destination); ((QueueSender) producer).send(message); } else { producer = ((TopicSession) session).createPublisher((Topic) destination); ((TopicPublisher) producer).publish(message); } if (log.isDebugEnabled()) { log.debug("Sent message to destination : " + destination + "\nMessage ID : " + message.getJMSMessageID() + "\nCorrelation ID : " + message.getJMSCorrelationID() + "\nReplyTo ID : " + message.getJMSReplyTo()); } } catch (JMSException e) { handleException("Error creating a producer or sending to : " + destination, e); } finally { if (producer != null) { try { producer.close(); } catch (JMSException ignore) { } } } }
From source file:org.artificer.events.jms.JMSEventProducer.java
private void publishEvent(Object payload, String type) { for (Destination destination : destinations) { MessageProducer producer = null; try {//from ww w. jav a2 s . com producer = session.createProducer(destination); TextMessage textMessage = session.createTextMessage(); textMessage.setJMSType(type); ObjectMapper mapper = new ObjectMapper(); String text = mapper.writeValueAsString(payload); textMessage.setText(text); producer.send(textMessage); } catch (Exception e) { LOG.error(e.getMessage(), e); } finally { if (producer != null) { try { producer.close(); } catch (Exception e) { } } } } }
From source file:org.frameworkset.mq.RequestDispatcher.java
public void send(int destinationType, String destination_, boolean persistent, int priority, long timeToLive, Message message, Logger step, JMSProperties properties) throws JMSException { if (step != null) step.logBasic("send message to " + destination_ + " assertStarted(),message=" + message); assertStarted();//from w ww . jav a2 s . c om MessageProducer producer = null; try { Destination destination = null; // boolean isqueue = destinationType == MQUtil.TYPE_QUEUE; // if (isqueue) // { // if(step != null) // step.logBasic("send message to " + destination_ // + " build QUEUE destination"); // destination = session.createQueue(destination_); // if(step != null) // step.logBasic("send message to " + destination_ // + " build QUEUE destination end"); // } // else // { // if(step != null) // step.logBasic("send message to " + destination_ // + " build Topic destination"); // destination = session.createTopic(destination_); // if(step != null) // step.logBasic("send message to " + destination_ // + " build Topic destination end"); // } if (step != null) step.logBasic("send message to " + destination_ + " build destination."); destination = this.connection.createDestination(session, destination_, destinationType); if (step != null) step.logBasic("send message to " + destination_ + " build destination end"); int deliveryMode = persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT; if (step != null) step.logBasic("send message to " + destination_ + " this.client.isPersistent =" + persistent); if (step != null) step.logBasic("send message to " + destination + " send started...."); producer = session.createProducer(destination); if (properties != null) MQUtil.initMessage(message, properties); producer.send(message, deliveryMode, priority, timeToLive); if (step != null) step.logBasic("send message to " + destination + " send end...."); if (LOG.isDebugEnabled()) { LOG.debug("Sent! to destination: " + destination + " message: " + message); } } catch (JMSException e) { throw e; } catch (Exception e) { throw new JMSException(e.getMessage()); } finally { if (producer != null) try { producer.close(); } catch (Exception e) { } } }
From source file:org.frameworkset.mq.RequestDispatcher.java
public void send(int destinationType, String destination_, boolean persistent, int priority, long timeToLive, Message message, JMSProperties properties) throws JMSException { LOG.debug("send message to " + destination_ + " assertStarted(),message=" + message); assertStarted();/*from ww w . j a va 2 s . co m*/ MessageProducer producer = null; try { Destination destination = null; // destinationType = JMSConnectionFactory.evaluateDestinationType(destination_, destinationType); // destination_ = JMSConnectionFactory.evaluateDestination(destination_); // boolean isqueue = destinationType == MQUtil.TYPE_QUEUE; // if (isqueue) // { // LOG.debug("send message to " + destination_ // + " build QUEUE destination"); // destination = session.createQueue(destination_); // LOG.debug("send message to " + destination_ // + " build QUEUE destination end"); // } // else // { // LOG.debug("send message to " + destination_ // + " build Topic destination"); // destination = session.createTopic(destination_); // LOG.debug("send message to " + destination_ // + " build Topic destination end"); // } LOG.debug("send message to " + destination_ + " build destination"); destination = connection.createDestination(session, destination_, destinationType); LOG.debug("send message to " + destination_ + " build destination end."); int deliveryMode = persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT; LOG.debug("send message to " + destination_ + " this.client.isPersistent =" + persistent); LOG.debug("send message to " + destination + " send started...."); producer = session.createProducer(destination); if (properties != null) MQUtil.initMessage(message, properties); producer.send(message, deliveryMode, priority, timeToLive); LOG.debug("send message to " + destination + " send end...."); if (LOG.isDebugEnabled()) { LOG.debug("Sent! to destination: " + destination + " message: " + message); } } catch (JMSException e) { throw e; } catch (Exception e) { throw new JMSException(e.getMessage()); } finally { if (producer != null) try { producer.close(); } catch (Exception e) { } } }
From source file:org.frameworkset.mq.RequestDispatcher.java
public void send(String msg, JMSProperties properties) throws JMSException { assertStarted();//from w w w . j a va 2 s .c o m MessageProducer producer = null; try { Destination destination = null; // if (this.destinationType == MQUtil.TYPE_QUEUE) // { // destination = session.createQueue(this.destination); // } // else // { // destination = session.createTopic(this.destination); // } LOG.debug("send message to " + this.destination + " build destination"); destination = connection.createDestination(session, this.destination, destinationType); LOG.debug("send message to " + this.destination + " build destination end."); int deliveryMode = this.persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT; producer = session.createProducer(destination); Message message = createTextMessage(msg); if (properties != null) MQUtil.initMessage(message, properties); producer.send(message, deliveryMode, this.priovity, this.timetolive); if (LOG.isDebugEnabled()) { LOG.debug("Sent! to destination: " + destination + " message: " + message); } } catch (JMSException e) { throw e; } catch (Exception e) { throw new JMSException(e.getMessage()); } finally { if (producer != null) try { producer.close(); } catch (Exception e) { } } }
From source file:org.frameworkset.mq.RequestDispatcher.java
public void send(int destinationType, String destination_, Message message, boolean persistent, int priority, long timeToLive, JMSProperties properties) throws JMSException { assertStarted();// w w w .j a va 2 s . c o m MessageProducer producer = null; try { Destination destination = null; // if (destinationType == MQUtil.TYPE_QUEUE) // { // destination = session.createQueue(destination_); // } // else // { // destination = session.createTopic(destination_); // } LOG.debug("send message to " + destination_ + " build destination"); destination = connection.createDestination(session, destination_, destinationType); LOG.debug("send message to " + destination_ + " build destination end."); int deliveryMode = persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT; producer = session.createProducer(destination); if (properties != null) MQUtil.initMessage(message, properties); producer.send(message, deliveryMode, priority, timeToLive); if (LOG.isDebugEnabled()) { LOG.debug("Sent! to destination: " + destination + " message: " + message); } message = null; } catch (JMSException e) { throw e; } catch (Exception e) { throw new JMSException(e.getMessage()); } finally { if (producer != null) try { producer.close(); } catch (Exception e) { } } }