List of usage examples for javax.jms MessageProducer close
void close() throws JMSException;
From source file:com.mirth.connect.connectors.jms.JmsUtils.java
public static void close(MessageProducer producer) throws JMSException { if (producer != null) { producer.close(); }/*from www .j a va2 s . c om*/ }
From source file:com.mirth.connect.connectors.jms.JmsUtils.java
public static void closeQuietly(MessageProducer producer) { if (producer != null) { try {// www . jav a 2 s. co m producer.close(); } catch (JMSException e) { logger.error("Failed to close jms message producer", e); } } }
From source file:org.logicblaze.lingo.jms.impl.DefaultJmsProducer.java
public void close() throws JMSException { if (producer != null) { MessageProducer tmp = producer; producer = null;/*from w w w. j a v a 2 s . co m*/ tmp.close(); } if (session != null) { Session tmp = session; session = null; tmp.close(); } if (connection != null) { Connection tmp = connection; connection = null; if (ownsConnection) { tmp.close(); } } }
From source file:org.fusesource.stompjms.JmsTestSupport.java
protected void safeClose(MessageProducer p) { try { p.close(); } catch (Throwable e) { } }
From source file:org.ct.amq.jdbc.security.JdbcAuthenticationPluginTest.java
public void testSecurityContextClearedOnPurge() throws Exception { connection.close();/*from w ww .j av a2 s . c o m*/ ActiveMQConnectionFactory tcpFactory = new ActiveMQConnectionFactory( broker.getTransportConnectors().get(0).getPublishableConnectString()); ActiveMQConnection conn = (ActiveMQConnection) tcpFactory.createConnection("user", "password"); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); conn.start(); final int numDests = broker.getRegionBroker().getDestinations().length; for (int i = 0; i < 10; i++) { MessageProducer p = sess.createProducer(new ActiveMQQueue("USERS.PURGE." + i)); p.close(); } assertTrue("dests are purged", Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { LOG.info( "dests, orig: " + numDests + ", now: " + broker.getRegionBroker().getDestinations().length); return (numDests + 1) == broker.getRegionBroker().getDestinations().length; } })); // verify removed from connection security context TransportConnection brokerConnection = broker.getTransportConnectors().get(0).getConnections().get(0); TransportConnectionState transportConnectionState = brokerConnection .lookupConnectionState(conn.getConnectionInfo().getConnectionId()); assertEquals("no destinations", 0, transportConnectionState.getContext().getSecurityContext().getAuthorizedWriteDests().size()); }
From source file:com.oneops.controller.jms.InductorPublisher.java
/** * Close connection./* w w w. j a v a2s . co m*/ */ public void closeConnection() { try { for (MessageProducer producer : bindingQueusMap.values()) { producer.close(); } session.close(); connection.close(); } catch (Exception ignore) { } }
From source file:org.fusesource.stompjms.JmsTestSupport.java
protected void sendMessages(Session session, Destination destination, int count) throws JMSException { MessageProducer producer = session.createProducer(destination); for (int i = 0; i < count; i++) { producer.send(session.createTextMessage(messageTextPrefix + i)); }//from w w w .j a va 2s. c o m producer.close(); }
From source file:eu.domibus.submission.jms.BackendJMSImpl.java
/** * This method is called when a message was received at the incoming queue * * @param message The incoming JMS Message *///from w w w. ja va 2s.c o m @Override public void onMessage(final Message message) { final MapMessage map = (MapMessage) message; try { final Connection con = this.cf.createConnection(); final Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE); final MapMessage res = session.createMapMessage(); try { final String messageID = this.submit(map); res.setStringProperty("messageId", messageID); } catch (final TransformationException | ValidationException e) { BackendJMSImpl.LOG.error("Exception occurred: ", e); res.setString("ErrorMessage", e.getMessage()); } res.setJMSCorrelationID(map.getJMSCorrelationID()); final MessageProducer sender = session.createProducer(this.outQueue); sender.setDeliveryMode(DeliveryMode.NON_PERSISTENT); sender.send(res); sender.close(); session.close(); con.close(); } catch (final JMSException ex) { BackendJMSImpl.LOG.error("Error while sending response to queue", ex); } }
From source file:com.cognifide.aet.runner.distribution.RunnerMessageListener.java
private void sendFatalMessage(Message wrapperMessage, String message) { try {/*w w w . ja v a 2 s . c o m*/ final Destination jmsReplyTo = wrapperMessage.getJMSReplyTo(); if (jmsReplyTo != null) { final MessageProducer producer = session.createProducer(jmsReplyTo); final FatalErrorMessage errorMessage = new FatalErrorMessage( "Failed to process test suite: " + message, wrapperMessage.getJMSCorrelationID()); producer.send(session.createObjectMessage(errorMessage)); producer.close(); } } catch (Exception e) { LOGGER.error("Fatal exception, can't deliver message {}!", message, e); } }
From source file:Supplier.java
public void run() { ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(user, password, url); Session session = null;/*from ww w.jav a 2s . c om*/ Destination orderQueue; try { Connection connection = connectionFactory.createConnection(); session = connection.createSession(true, Session.SESSION_TRANSACTED); orderQueue = session.createQueue(QUEUE); MessageConsumer consumer = session.createConsumer(orderQueue); connection.start(); while (true) { Message message = consumer.receive(); MessageProducer producer = session.createProducer(message.getJMSReplyTo()); MapMessage orderMessage; if (message instanceof MapMessage) { orderMessage = (MapMessage) message; } else { // End of Stream producer.send(session.createMessage()); session.commit(); producer.close(); break; } int quantity = orderMessage.getInt("Quantity"); System.out.println( ITEM + " Supplier: Vendor ordered " + quantity + " " + orderMessage.getString("Item")); MapMessage outMessage = session.createMapMessage(); outMessage.setInt("VendorOrderNumber", orderMessage.getInt("VendorOrderNumber")); outMessage.setString("Item", ITEM); quantity = Math.min(orderMessage.getInt("Quantity"), new Random().nextInt(orderMessage.getInt("Quantity") * 10)); outMessage.setInt("Quantity", quantity); producer.send(outMessage); System.out.println(ITEM + " Supplier: Sent " + quantity + " " + ITEM + "(s)"); session.commit(); System.out.println(ITEM + " Supplier: committed transaction"); producer.close(); } connection.close(); } catch (JMSException e) { e.printStackTrace(); } }