List of usage examples for javax.jms Session AUTO_ACKNOWLEDGE
int AUTO_ACKNOWLEDGE
To view the source code for javax.jms Session AUTO_ACKNOWLEDGE.
Click Source Link
From source file:org.firstopen.singularity.util.JMSUtil.java
public static void deliverMessageToQueue(String host, String queueName, String xml) { log.debug("IntegrationMod.deliverMessageToQueue queueName = " + queueName + " and doc = " + xml); MessageProducer m_sender = null;/* w ww.j a v a2 s .c om*/ Session m_session = null; Connection connection = null; char test = queueName.charAt(0); if (test == '/') queueName = queueName.substring(1); try { InitialContext context = JNDIUtil.getInitialContext(host); ConnectionFactory qcf = (ConnectionFactory) context.lookup("ConnectionFactory"); Queue queue = (Queue) context.lookup("queue/" + queueName); connection = qcf.createConnection(); m_session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); m_sender = m_session.createProducer(queue); TextMessage message = m_session.createTextMessage(); log.debug("message value is -> " + xml); message.setText(xml); m_sender.send(message); } catch (Exception e) { log.error("IntegrationMod.deliverMessageToQueue() Exception = ", e); } finally { if (connection != null) { try { connection.close(); } catch (JMSException e) { log.error("unable ot close JMS Connection", e); } } } }
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 {//from w w w . ja v a 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.ConcurrentProducerDurableConsumerTest.java
protected TopicSubscriber createDurableSubscriber(Connection conn, Destination dest, String name) throws Exception { conn.setClientID(name);/*from ww w . ja v a2 s . c o m*/ connections.add(conn); conn.start(); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); final TopicSubscriber consumer = sess.createDurableSubscriber((javax.jms.Topic) dest, name); return consumer; }
From source file:org.genemania.broker.Worker.java
private void startNewConnection() throws JMSException { PooledConnectionFactory connectionFactory = new PooledConnectionFactory(brokerUrl); Connection connection = connectionFactory.createConnection(); connection.setExceptionListener(this); connection.start();//from w w w. j a v a2 s . c om session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); responseHandler = session.createProducer(null); Queue requestsQueue = session.createQueue(mqRequestsQueueName); requestHandler = session.createConsumer(requestsQueue); requestHandler.setMessageListener(this); LOG.info("Listening to " + requestsQueue.getQueueName()); }
From source file:ConsumerTool.java
public void setAckMode(String ackMode) { if ("CLIENT_ACKNOWLEDGE".equals(ackMode)) { this.ackMode = Session.CLIENT_ACKNOWLEDGE; }/*www. j a va 2s . co m*/ if ("AUTO_ACKNOWLEDGE".equals(ackMode)) { this.ackMode = Session.AUTO_ACKNOWLEDGE; } if ("DUPS_OK_ACKNOWLEDGE".equals(ackMode)) { this.ackMode = Session.DUPS_OK_ACKNOWLEDGE; } if ("SESSION_TRANSACTED".equals(ackMode)) { this.ackMode = Session.SESSION_TRANSACTED; } }
From source file:org.springframework.jms.connection.ConnectionFactoryUtils.java
/** * Obtain a JMS TopicSession that is synchronized with the current transaction, if any. * <p>Mainly intended for use with the JMS 1.0.2 API. * @param cf the ConnectionFactory to obtain a Session for * @param existingCon the existing JMS Connection to obtain a Session for * (may be {@code null})//w w w. java 2s. co m * @param synchedLocalTransactionAllowed whether to allow for a local JMS transaction * that is synchronized with a Spring-managed transaction (where the main transaction * might be a JDBC-based one for a specific DataSource, for example), with the JMS * transaction committing right after the main transaction. If not allowed, the given * ConnectionFactory needs to handle transaction enlistment underneath the covers. * @return the transactional Session, or {@code null} if none found * @throws JMSException in case of JMS failure */ @Nullable public static TopicSession getTransactionalTopicSession(final TopicConnectionFactory cf, @Nullable final TopicConnection existingCon, final boolean synchedLocalTransactionAllowed) throws JMSException { return (TopicSession) doGetTransactionalSession(cf, new ResourceFactory() { @Override @Nullable public Session getSession(JmsResourceHolder holder) { return holder.getSession(TopicSession.class, existingCon); } @Override @Nullable public Connection getConnection(JmsResourceHolder holder) { return (existingCon != null ? existingCon : holder.getConnection(TopicConnection.class)); } @Override public Connection createConnection() throws JMSException { return cf.createTopicConnection(); } @Override public Session createSession(Connection con) throws JMSException { return ((TopicConnection) con).createTopicSession(synchedLocalTransactionAllowed, Session.AUTO_ACKNOWLEDGE); } @Override public boolean isSynchedLocalTransactionAllowed() { return synchedLocalTransactionAllowed; } }, true); }
From source file:org.apache.activemq.usecases.RequestReplyToTopicViaThreeNetworkHopsTest.java
/** * TEST QUEUES//from w w w. java 2 s. co m */ public void testQueue(String prod_broker_url, String cons_broker_url) throws Exception { int num_msg; Connection conn; Session sess; String queue_name; Destination cons_dest; num_msg = 5; LOG.info("TESTING QUEUES " + prod_broker_url + " -> " + cons_broker_url + " (" + num_msg + " messages)"); conn = createConnection(cons_broker_url); conn.start(); sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); // // Create the destination on which messages are being tested. // queue_name = "topotest2.perm.queue"; LOG.trace("Removing existing Queue"); removeQueue(conn, queue_name); LOG.trace("Creating Queue, " + queue_name); cons_dest = sess.createQueue(queue_name); testOneDest(conn, sess, cons_dest, num_msg); removeQueue(conn, queue_name); sess.close(); conn.close(); }
From source file:org.wso2.carbon.bpmn.extensions.jms.JMSConnectionFactory.java
/** * * @param connection//from w w w . java 2 s . co m * @return * create a session object and return it. */ private Session createSession(Connection connection) { Session session = null; try { //session is always not transacted session = JMSUtils.createSession(connection, false, Session.AUTO_ACKNOWLEDGE, isQueue()); if (log.isDebugEnabled()) { log.debug("New JMS Session was created from the JMS Connection"); } } catch (JMSException e) { log.error("Error creating a session from the JMS Connection using properties: " + parameters, e); } return session; }
From source file:nl.nn.adapterframework.extensions.tibco.SendTibcoMessage.java
public String doPipeWithTimeoutGuarded(Object input, IPipeLineSession session) throws PipeRunException { Connection connection = null; Session jSession = null;/* ww w .j av a 2s . c o m*/ MessageProducer msgProducer = null; Destination destination = null; String url_work; String authAlias_work; String userName_work; String password_work; String queueName_work; String messageProtocol_work; int replyTimeout_work; String soapAction_work; String result = null; ParameterValueList pvl = null; if (getParameterList() != null) { ParameterResolutionContext prc = new ParameterResolutionContext((String) input, session); try { pvl = prc.getValues(getParameterList()); } catch (ParameterException e) { throw new PipeRunException(this, getLogPrefix(session) + "exception on extracting parameters", e); } } url_work = getParameterValue(pvl, "url"); if (url_work == null) { url_work = getUrl(); } authAlias_work = getParameterValue(pvl, "authAlias"); if (authAlias_work == null) { authAlias_work = getAuthAlias(); } userName_work = getParameterValue(pvl, "userName"); if (userName_work == null) { userName_work = getUserName(); } password_work = getParameterValue(pvl, "password"); if (password_work == null) { password_work = getPassword(); } queueName_work = getParameterValue(pvl, "queueName"); if (queueName_work == null) { queueName_work = getQueueName(); } messageProtocol_work = getParameterValue(pvl, "messageProtocol"); if (messageProtocol_work == null) { messageProtocol_work = getMessageProtocol(); } String replyTimeout_work_str = getParameterValue(pvl, "replyTimeout"); if (replyTimeout_work_str == null) { replyTimeout_work = getReplyTimeout(); } else { replyTimeout_work = Integer.parseInt(replyTimeout_work_str); } soapAction_work = getParameterValue(pvl, "soapAction"); if (soapAction_work == null) soapAction_work = getSoapAction(); if (StringUtils.isEmpty(soapAction_work) && !StringUtils.isEmpty(queueName_work)) { String[] q = queueName_work.split("\\."); if (q.length > 0) { if (q[0].equalsIgnoreCase("P2P") && q.length >= 4) { soapAction_work = q[3]; } else if (q[0].equalsIgnoreCase("ESB") && q.length == 8) { soapAction_work = q[5] + "_" + q[6]; } else if (q[0].equalsIgnoreCase("ESB") && q.length > 8) { soapAction_work = q[6] + "_" + q[7]; } } } if (StringUtils.isEmpty(soapAction_work)) { log.debug(getLogPrefix(session) + "deriving default soapAction"); try { URL resource = ClassUtils.getResourceURL(this, "/xml/xsl/esb/soapAction.xsl"); TransformerPool tp = new TransformerPool(resource, true); soapAction_work = tp.transform(input.toString(), null); } catch (Exception e) { log.error(getLogPrefix(session) + "failed to execute soapAction.xsl"); } } if (messageProtocol_work == null) { throw new PipeRunException(this, getLogPrefix(session) + "messageProtocol must be set"); } if (!messageProtocol_work.equalsIgnoreCase(REQUEST_REPLY) && !messageProtocol_work.equalsIgnoreCase(FIRE_AND_FORGET)) { throw new PipeRunException(this, getLogPrefix(session) + "illegal value for messageProtocol [" + messageProtocol_work + "], must be '" + REQUEST_REPLY + "' or '" + FIRE_AND_FORGET + "'"); } CredentialFactory cf = new CredentialFactory(authAlias_work, userName_work, password_work); try { TibjmsAdmin admin; try { admin = TibcoUtils.getActiveServerAdmin(url_work, cf); } catch (TibjmsAdminException e) { log.debug(getLogPrefix(session) + "caught exception", e); admin = null; } if (admin != null) { QueueInfo queueInfo; try { queueInfo = admin.getQueue(queueName_work); } catch (Exception e) { throw new PipeRunException(this, getLogPrefix(session) + " exception on getting queue info", e); } if (queueInfo == null) { throw new PipeRunException(this, getLogPrefix(session) + " queue [" + queueName_work + "] does not exist"); } try { admin.close(); } catch (TibjmsAdminException e) { log.warn(getLogPrefix(session) + "exception on closing Tibjms Admin", e); } } ConnectionFactory factory = new com.tibco.tibjms.TibjmsConnectionFactory(url_work); connection = factory.createConnection(cf.getUsername(), cf.getPassword()); jSession = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE); destination = jSession.createQueue(queueName_work); msgProducer = jSession.createProducer(destination); TextMessage msg = jSession.createTextMessage(); msg.setText(input.toString()); Destination replyQueue = null; if (messageProtocol_work.equalsIgnoreCase(REQUEST_REPLY)) { replyQueue = jSession.createTemporaryQueue(); msg.setJMSReplyTo(replyQueue); msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT); msgProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); msgProducer.setTimeToLive(replyTimeout_work); } else { msg.setJMSDeliveryMode(DeliveryMode.PERSISTENT); msgProducer.setDeliveryMode(DeliveryMode.PERSISTENT); } if (StringUtils.isNotEmpty(soapAction_work)) { log.debug( getLogPrefix(session) + "setting [SoapAction] property to value [" + soapAction_work + "]"); msg.setStringProperty("SoapAction", soapAction_work); } msgProducer.send(msg); if (log.isDebugEnabled()) { log.debug(getLogPrefix(session) + "sent message [" + msg.getText() + "] " + "to [" + msgProducer.getDestination() + "] " + "msgID [" + msg.getJMSMessageID() + "] " + "correlationID [" + msg.getJMSCorrelationID() + "] " + "replyTo [" + msg.getJMSReplyTo() + "]"); } else { if (log.isInfoEnabled()) { log.info(getLogPrefix(session) + "sent message to [" + msgProducer.getDestination() + "] " + "msgID [" + msg.getJMSMessageID() + "] " + "correlationID [" + msg.getJMSCorrelationID() + "] " + "replyTo [" + msg.getJMSReplyTo() + "]"); } } if (messageProtocol_work.equalsIgnoreCase(REQUEST_REPLY)) { String replyCorrelationId = msg.getJMSMessageID(); MessageConsumer msgConsumer = jSession.createConsumer(replyQueue, "JMSCorrelationID='" + replyCorrelationId + "'"); log.debug(getLogPrefix(session) + "] start waiting for reply on [" + replyQueue + "] selector [" + replyCorrelationId + "] for [" + replyTimeout_work + "] ms"); try { connection.start(); Message rawReplyMsg = msgConsumer.receive(replyTimeout_work); if (rawReplyMsg == null) { throw new PipeRunException(this, getLogPrefix(session) + "did not receive reply on [" + replyQueue + "] replyCorrelationId [" + replyCorrelationId + "] within [" + replyTimeout_work + "] ms"); } TextMessage replyMsg = (TextMessage) rawReplyMsg; result = replyMsg.getText(); } finally { } } else { result = msg.getJMSMessageID(); } } catch (JMSException e) { throw new PipeRunException(this, getLogPrefix(session) + " exception on sending message to Tibco queue", e); } finally { if (connection != null) { try { connection.close(); } catch (JMSException e) { log.warn(getLogPrefix(session) + "exception on closing connection", e); } } } return result; }
From source file:org.apache.qpid.client.ssl.SSLTest.java
public void testCreateSSLConnectionUsingConnectionURLParamsTrustStoreOnly() throws Exception { if (shouldPerformTest()) { clearSslStoreSystemProperties(); //Start the broker (WANTing client certificate authentication) configureJavaBrokerIfNecessary(true, true, false, true); super.setUp(); String url = "amqp://guest:guest@test/?brokerlist='tcp://localhost:%s" + "?ssl='true'&ssl_verify_hostname='true'" + "&trust_store='%s'&trust_store_password='%s'" + "'"; url = String.format(url, QpidBrokerTestCase.DEFAULT_SSL_PORT, TRUSTSTORE, TRUSTSTORE_PASSWORD); Connection con = getConnection(new AMQConnectionURL(url)); assertNotNull("connection should be successful", con); Session ssn = con.createSession(false, Session.AUTO_ACKNOWLEDGE); assertNotNull("create session should be successful", ssn); }//from www.j a v a 2 s. co m }