Java Code Examples for javax.jms.Session#SESSION_TRANSACTED
The following examples show how to use
javax.jms.Session#SESSION_TRANSACTED .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JmsConnection.java From qpid-jms with Apache License 2.0 | 6 votes |
protected int getSessionAcknowledgeMode(boolean transacted, int acknowledgeMode) throws JMSException { int result = acknowledgeMode; if (!transacted && acknowledgeMode == Session.SESSION_TRANSACTED) { throw new JMSException("acknowledgeMode SESSION_TRANSACTED cannot be used for an non-transacted Session"); } if (transacted) { result = Session.SESSION_TRANSACTED; } else { try { JmsSession.validateSessionMode(acknowledgeMode); } catch (JMSRuntimeException jmsre) { throw new JMSException("acknowledgeMode " + acknowledgeMode + " cannot be used for an non-transacted Session"); } } return result; }
Example 2
Source File: AbruptClientDisconnectTest.java From qpid-broker-j with Apache License 2.0 | 6 votes |
@Test public void messagingOnAbruptConnectivityLostWhilstPublishing() throws Exception { final ClientMonitor clientMonitor = new ClientMonitor(); _tunneledConnection = createTunneledConnection(clientMonitor); Producer producer = new Producer(_tunneledConnection, _testQueue, Session.SESSION_TRANSACTED, 10, () -> _tcpTunneler.disconnect(clientMonitor.getClientAddress()) ); _executorService.submit(producer); boolean disconnected = clientMonitor.awaitDisconnect(10, TimeUnit.SECONDS); producer.stop(); assertTrue("Client disconnect did not happen", disconnected); assertTrue("Unexpected number of published messages " + producer.getNumberOfPublished(), producer.getNumberOfPublished() >= 10); consumeIgnoringLastSeenOmission(_utilityConnection, _testQueue, 0, producer.getNumberOfPublished(), -1); }
Example 3
Source File: ClientJmsDelegate.java From qpid-broker-j with Apache License 2.0 | 6 votes |
public void createSession(final CreateSessionCommand command) { try { final Connection connection = _testConnections.get(command.getConnectionName()); if (connection == null) { throw new DistributedTestException("No test connection found called: " + command.getConnectionName(), command); } final boolean transacted = command.getAcknowledgeMode() == Session.SESSION_TRANSACTED; final Session newSession = connection.createSession(transacted, command.getAcknowledgeMode()); LOGGER.debug("Created session {} with transacted = {} and acknowledgeMode = {}", command.getSessionName(), newSession.getTransacted(), newSession.getAcknowledgeMode()); addSession(command.getSessionName(), newSession); _testSessionToConnections.put(newSession, connection); } catch (final JMSException jmse) { throw new DistributedTestException("Unable to create new session: " + command, jmse); } }
Example 4
Source File: StandardJmsActivationSpecFactory.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Apply the specified acknowledge mode to the ActivationSpec object. * <p>This implementation applies the standard JCA 1.5 acknowledge modes * "Auto-acknowledge" and "Dups-ok-acknowledge". It throws an exception in * case of {@code CLIENT_ACKNOWLEDGE} or {@code SESSION_TRANSACTED} * having been requested. * @param bw the BeanWrapper wrapping the ActivationSpec object * @param ackMode the configured acknowledge mode * (according to the constants in {@link javax.jms.Session} * @see javax.jms.Session#AUTO_ACKNOWLEDGE * @see javax.jms.Session#DUPS_OK_ACKNOWLEDGE * @see javax.jms.Session#CLIENT_ACKNOWLEDGE * @see javax.jms.Session#SESSION_TRANSACTED */ protected void applyAcknowledgeMode(BeanWrapper bw, int ackMode) { if (ackMode == Session.SESSION_TRANSACTED) { throw new IllegalArgumentException("No support for SESSION_TRANSACTED: Only \"Auto-acknowledge\" " + "and \"Dups-ok-acknowledge\" supported in standard JCA 1.5"); } else if (ackMode == Session.CLIENT_ACKNOWLEDGE) { throw new IllegalArgumentException("No support for CLIENT_ACKNOWLEDGE: Only \"Auto-acknowledge\" " + "and \"Dups-ok-acknowledge\" supported in standard JCA 1.5"); } else if (bw.isWritableProperty("acknowledgeMode")) { bw.setPropertyValue("acknowledgeMode", ackMode == Session.DUPS_OK_ACKNOWLEDGE ? "Dups-ok-acknowledge" : "Auto-acknowledge"); } else if (ackMode == Session.DUPS_OK_ACKNOWLEDGE) { // Standard JCA 1.5 "acknowledgeMode" apparently not supported (e.g. WebSphere MQ 6.0.2.1) throw new IllegalArgumentException( "Dups-ok-acknowledge not supported by underlying provider: " + this.activationSpecClass.getName()); } }
Example 5
Source File: SingleConnectionFactory.java From java-technology-stack with MIT License | 6 votes |
/** * Create a default Session for this ConnectionFactory, * adapting to JMS 1.0.2 style queue/topic mode if necessary. * @param con the JMS Connection to operate on * @param mode the Session acknowledgement mode * ({@code Session.TRANSACTED} or one of the common modes) * @return the newly created Session * @throws JMSException if thrown by the JMS API */ protected Session createSession(Connection con, Integer mode) throws JMSException { // Determine JMS API arguments... boolean transacted = (mode == Session.SESSION_TRANSACTED); int ackMode = (transacted ? Session.AUTO_ACKNOWLEDGE : mode); // Now actually call the appropriate JMS factory method... if (Boolean.FALSE.equals(this.pubSubMode) && con instanceof QueueConnection) { return ((QueueConnection) con).createQueueSession(transacted, ackMode); } else if (Boolean.TRUE.equals(this.pubSubMode) && con instanceof TopicConnection) { return ((TopicConnection) con).createTopicSession(transacted, ackMode); } else { return con.createSession(transacted, ackMode); } }
Example 6
Source File: AbstractListenerContainerParser.java From spring4-understanding with Apache License 2.0 | 6 votes |
protected Integer parseAcknowledgeMode(Element ele, ParserContext parserContext) { String acknowledge = ele.getAttribute(ACKNOWLEDGE_ATTRIBUTE); if (StringUtils.hasText(acknowledge)) { int acknowledgeMode = Session.AUTO_ACKNOWLEDGE; if (ACKNOWLEDGE_TRANSACTED.equals(acknowledge)) { acknowledgeMode = Session.SESSION_TRANSACTED; } else if (ACKNOWLEDGE_DUPS_OK.equals(acknowledge)) { acknowledgeMode = Session.DUPS_OK_ACKNOWLEDGE; } else if (ACKNOWLEDGE_CLIENT.equals(acknowledge)) { acknowledgeMode = Session.CLIENT_ACKNOWLEDGE; } else if (!ACKNOWLEDGE_AUTO.equals(acknowledge)) { parserContext.getReaderContext().error("Invalid listener container 'acknowledge' setting [" + acknowledge + "]: only \"auto\", \"client\", \"dups-ok\" and \"transacted\" supported.", ele); } return acknowledgeMode; } else { return null; } }
Example 7
Source File: StandardJmsActivationSpecFactory.java From spring-analysis-note with MIT License | 6 votes |
/** * Apply the specified acknowledge mode to the ActivationSpec object. * <p>This implementation applies the standard JCA 1.5 acknowledge modes * "Auto-acknowledge" and "Dups-ok-acknowledge". It throws an exception in * case of {@code CLIENT_ACKNOWLEDGE} or {@code SESSION_TRANSACTED} * having been requested. * @param bw the BeanWrapper wrapping the ActivationSpec object * @param ackMode the configured acknowledge mode * (according to the constants in {@link javax.jms.Session} * @see javax.jms.Session#AUTO_ACKNOWLEDGE * @see javax.jms.Session#DUPS_OK_ACKNOWLEDGE * @see javax.jms.Session#CLIENT_ACKNOWLEDGE * @see javax.jms.Session#SESSION_TRANSACTED */ protected void applyAcknowledgeMode(BeanWrapper bw, int ackMode) { if (ackMode == Session.SESSION_TRANSACTED) { throw new IllegalArgumentException("No support for SESSION_TRANSACTED: Only \"Auto-acknowledge\" " + "and \"Dups-ok-acknowledge\" supported in standard JCA 1.5"); } else if (ackMode == Session.CLIENT_ACKNOWLEDGE) { throw new IllegalArgumentException("No support for CLIENT_ACKNOWLEDGE: Only \"Auto-acknowledge\" " + "and \"Dups-ok-acknowledge\" supported in standard JCA 1.5"); } else if (bw.isWritableProperty("acknowledgeMode")) { bw.setPropertyValue("acknowledgeMode", ackMode == Session.DUPS_OK_ACKNOWLEDGE ? "Dups-ok-acknowledge" : "Auto-acknowledge"); } else if (ackMode == Session.DUPS_OK_ACKNOWLEDGE) { // Standard JCA 1.5 "acknowledgeMode" apparently not supported (e.g. WebSphere MQ 6.0.2.1) throw new IllegalArgumentException("Dups-ok-acknowledge not supported by underlying provider"); } }
Example 8
Source File: DefaultJmsActivationSpecFactory.java From java-technology-stack with MIT License | 5 votes |
/** * This implementation maps {@code SESSION_TRANSACTED} onto an * ActivationSpec property named "useRAManagedTransaction", if available * (following ActiveMQ's naming conventions). */ @Override protected void applyAcknowledgeMode(BeanWrapper bw, int ackMode) { if (ackMode == Session.SESSION_TRANSACTED && bw.isWritableProperty("useRAManagedTransaction")) { // ActiveMQ bw.setPropertyValue("useRAManagedTransaction", "true"); } else { super.applyAcknowledgeMode(bw, ackMode); } }
Example 9
Source File: ActiveMQConnection.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * I'm keeping this as static as the same check will be done within RA. * This is to conform with TCK Tests where we must return ackMode exactly as they want if transacted=false */ public static int checkAck(boolean transacted, int acknowledgeMode) { if (!transacted && acknowledgeMode == Session.SESSION_TRANSACTED) { return Session.AUTO_ACKNOWLEDGE; } return acknowledgeMode; }
Example 10
Source File: MockJMSConnection.java From pooled-jms with Apache License 2.0 | 5 votes |
protected int getSessionAcknowledgeMode(boolean transacted, int acknowledgeMode) throws JMSException { int result = acknowledgeMode; if (!transacted && acknowledgeMode == Session.SESSION_TRANSACTED) { throw new JMSException("acknowledgeMode SESSION_TRANSACTED cannot be used for an non-transacted Session"); } if (transacted) { result = Session.SESSION_TRANSACTED; } else if (acknowledgeMode < Session.SESSION_TRANSACTED || acknowledgeMode > Session.DUPS_OK_ACKNOWLEDGE){ throw new JMSException("acknowledgeMode " + acknowledgeMode + " cannot be used for an non-transacted Session"); } return result; }
Example 11
Source File: TomEEConnection.java From tomee with Apache License 2.0 | 5 votes |
@Override public Session createSession(boolean transacted, int acknowledgeMode) throws JMSException { checkClosedOrFailed(); ensureConnectionInfoSent(); if (!transacted) { if (acknowledgeMode == Session.SESSION_TRANSACTED) { throw new JMSException("acknowledgeMode SESSION_TRANSACTED cannot be used for an non-transacted Session"); } else if (acknowledgeMode < Session.SESSION_TRANSACTED || acknowledgeMode > ActiveMQSession.MAX_ACK_CONSTANT) { throw new JMSException("invalid acknowledgeMode: " + acknowledgeMode + ". Valid values are Session.AUTO_ACKNOWLEDGE (1), " + "Session.CLIENT_ACKNOWLEDGE (2), Session.DUPS_OK_ACKNOWLEDGE (3), ActiveMQSession.INDIVIDUAL_ACKNOWLEDGE (4) or for transacted sessions Session.SESSION_TRANSACTED (0)"); } } return new TomEESession(this, getNextSessionId(), transacted ? Session.SESSION_TRANSACTED : acknowledgeMode, isDispatchAsync(), isAlwaysSessionAsync()); }
Example 12
Source File: AcknowledgeTest.java From qpid-broker-j with Apache License 2.0 | 5 votes |
private void acknowledge(final int ackMode, final Session session, final Message message) throws JMSException { switch(ackMode) { case Session.SESSION_TRANSACTED: session.commit(); break; case Session.CLIENT_ACKNOWLEDGE: message.acknowledge(); break; default: } }
Example 13
Source File: TomEEXAConnection.java From tomee with Apache License 2.0 | 4 votes |
@Override public Session createSession(final int sessionMode) throws JMSException { return super.createSession(sessionMode == Session.SESSION_TRANSACTED, sessionMode); }
Example 14
Source File: JMSMessageListenerWrapper.java From activemq-artemis with Apache License 2.0 | 4 votes |
protected JMSMessageListenerWrapper(final ConnectionFactoryOptions options, final ActiveMQConnection connection, final ActiveMQSession session, final ClientConsumer consumer, final MessageListener listener, final int ackMode) { this.options = options; this.connection = connection; this.session = session; this.consumer = consumer; this.listener = listener; transactedOrClientAck = (ackMode == Session.SESSION_TRANSACTED || ackMode == Session.CLIENT_ACKNOWLEDGE) || session.isXA(); individualACK = (ackMode == ActiveMQJMSConstants.INDIVIDUAL_ACKNOWLEDGE); clientACK = (ackMode == Session.CLIENT_ACKNOWLEDGE); }
Example 15
Source File: AbstractMessageListenerContainer.java From cxf with Apache License 2.0 | 4 votes |
public void setTransacted(boolean transacted) { this.transacted = transacted; if (this.transacted) { this.acknowledgeMode = Session.SESSION_TRANSACTED; } }
Example 16
Source File: JMSSenderWorker.java From maestro-java with Apache License 2.0 | 4 votes |
private boolean isSessionTransacted(JmsOptions opts) { return opts.getSessionMode() == Session.SESSION_TRANSACTED && opts.getBatchAcknowledge() > 0; }
Example 17
Source File: AbruptClientDisconnectTest.java From qpid-broker-j with Apache License 2.0 | 4 votes |
@Test public void messagingOnAbruptConnectivityLostWhilstConsuming() throws Exception { int minimumNumberOfMessagesToProduce = 40; int minimumNumberOfMessagesToConsume = 20; // produce minimum required number of messages before starting consumption final CountDownLatch queueDataWaiter = new CountDownLatch(1); final Producer producer = new Producer(_utilityConnection, _testQueue, Session.SESSION_TRANSACTED, minimumNumberOfMessagesToProduce, queueDataWaiter::countDown); // create tunneled connection to consume messages final ClientMonitor clientMonitor = new ClientMonitor(); _tunneledConnection = createTunneledConnection(clientMonitor); _tunneledConnection.start(); // consumer will consume minimum number of messages before abrupt disconnect Consumer consumer = new Consumer(_tunneledConnection, _testQueue, Session.SESSION_TRANSACTED, minimumNumberOfMessagesToConsume, () -> { try { _tcpTunneler.disconnect(clientMonitor.getClientAddress()); } finally { producer.stop(); } } ); LOGGER.debug("Waiting for producer to produce {} messages before consuming", minimumNumberOfMessagesToProduce); _executorService.submit(producer); assertTrue("Latch waiting for produced messages was not count down", queueDataWaiter.await(10, TimeUnit.SECONDS)); LOGGER.debug("Producer sent {} messages. Starting consumption...", producer.getNumberOfPublished()); _executorService.submit(consumer); boolean disconnectOccurred = clientMonitor.awaitDisconnect(10, TimeUnit.SECONDS); LOGGER.debug("Stopping consumer and producer"); consumer.stop(); producer.stop(); LOGGER.debug("Producer sent {} messages. Consumer received {} messages", producer.getNumberOfPublished(), consumer.getNumberOfConsumed()); assertTrue("Client disconnect did not happen", disconnectOccurred); assertTrue("Unexpected number of published messages " + producer.getNumberOfPublished(), producer.getNumberOfPublished() >= minimumNumberOfMessagesToProduce); assertTrue("Unexpected number of consumed messages " + consumer.getNumberOfConsumed(), consumer.getNumberOfConsumed() >= minimumNumberOfMessagesToConsume); LOGGER.debug("Remaining number to consume {}.", (producer.getNumberOfPublished() - consumer.getNumberOfConsumed())); consumeIgnoringLastSeenOmission(_utilityConnection, _testQueue, consumer.getNumberOfConsumed(), producer.getNumberOfPublished(), consumer.getLastSeenMessageIndex()); }
Example 18
Source File: JmsSessionInfo.java From qpid-jms with Apache License 2.0 | 4 votes |
public boolean isTransacted() { return acknowledgementMode == Session.SESSION_TRANSACTED; }
Example 19
Source File: ActiveMqSender.java From tangyuan2 with GNU General Public License v3.0 | 4 votes |
private void sendTopicMessage(ActiveMqChannelVo queue, Object arg, boolean useTx, MqServiceContext context) throws Throwable { ActiveMqSource mqSource = (ActiveMqSource) MqContainer.getInstance().getMqSourceManager().getMqSource(queue.getMsKey()); Connection connection = null; Session session = null; Throwable tx = null; boolean transacted = false; int acknowledgeMode = Session.AUTO_ACKNOWLEDGE; if (useTx) { transacted = true; acknowledgeMode = Session.SESSION_TRANSACTED; } try { session = mqSource.getSession(transacted, acknowledgeMode); if (null == session) { connection = mqSource.getConnection(); session = connection.createSession(transacted, acknowledgeMode); } if (useTx) { context.addTransactionObject(new ActiveMqTransactionObject(mqSource, session)); } Destination destination = session.createTopic(queue.getName()); MessageProducer messageProducer = session.createProducer(destination); TextMessage message = session.createTextMessage(((XCO) arg).toXMLString()); // int deliveryMode = (Integer) queue.getProperties().get(ActiveMqVo.ACTIVEMQ_P_DELIVERYMODE); // long timeToLive = (Long) queue.getProperties().get(ActiveMqVo.ACTIVEMQ_P_TIMETOLIVE); int deliveryMode = queue.getDeliveryMode(); long timeToLive = queue.getTimeToLive(); messageProducer.send(message, deliveryMode, Message.DEFAULT_PRIORITY, timeToLive); log.info("send message to topic[" + queue.getName() + "]: " + ((XCO) arg).toXMLString()); } catch (Throwable e) { tx = e; } finally { if (null != session && !useTx) { mqSource.closeSession(session, transacted); } if (null != tx) { throw tx; } } }
Example 20
Source File: JMSConnectionFactory.java From micro-integrator with Apache License 2.0 | 4 votes |
public JMSConnectionFactory(Properties properties) { try { ctx = new InitialContext(properties); } catch (NamingException e) { logger.error("NamingException while obtaining initial context. " + e.getMessage(), e); } String connectionFactoryType = properties.getProperty(JMSConstants.CONNECTION_FACTORY_TYPE); if ("topic".equals(connectionFactoryType)) { this.destinationType = JMSConstants.JMSDestinationType.TOPIC; } else { this.destinationType = JMSConstants.JMSDestinationType.QUEUE; } if (properties.getProperty(JMSConstants.PARAM_JMS_SPEC_VER) == null || JMSConstants.JMS_SPEC_VERSION_1_1 .equals(properties.getProperty(JMSConstants.PARAM_JMS_SPEC_VER))) { jmsSpec = JMSConstants.JMS_SPEC_VERSION_1_1; } else if (JMSConstants.JMS_SPEC_VERSION_2_0.equals(properties.getProperty(JMSConstants.PARAM_JMS_SPEC_VER))) { jmsSpec = JMSConstants.JMS_SPEC_VERSION_2_0; } else { jmsSpec = JMSConstants.JMS_SPEC_VERSION_1_0; } if ("true".equalsIgnoreCase(properties.getProperty(JMSConstants.PARAM_IS_SHARED_SUBSCRIPTION))) { isSharedSubscription = true; } else { isSharedSubscription = false; } noPubSubLocal = Boolean.valueOf(properties.getProperty(JMSConstants.PARAM_PUBSUB_NO_LOCAL)); clientId = properties.getProperty(JMSConstants.PARAM_DURABLE_SUB_CLIENT_ID); subscriptionName = properties.getProperty(JMSConstants.PARAM_DURABLE_SUB_NAME); if (isSharedSubscription) { if (subscriptionName == null) { logger.info("Subscription name is not given. Therefor declaring a non-shared subscription"); isSharedSubscription = false; } } String subDurable = properties.getProperty(JMSConstants.PARAM_SUB_DURABLE); if (subDurable != null) { isDurable = Boolean.parseBoolean(subDurable); } String msgSelector = properties.getProperty(JMSConstants.PARAM_MSG_SELECTOR); if (msgSelector != null) { messageSelector = msgSelector; } this.connectionFactoryString = properties.getProperty(JMSConstants.CONNECTION_FACTORY_JNDI_NAME); if (connectionFactoryString == null || "".equals(connectionFactoryString)) { connectionFactoryString = "QueueConnectionFactory"; } this.destinationName = properties.getProperty(JMSConstants.DESTINATION_NAME); if (destinationName == null || "".equals(destinationName)) { destinationName = "QUEUE_" + System.currentTimeMillis(); } String strTransactedSession = properties.getProperty(JMSConstants.SESSION_TRANSACTED); if (strTransactedSession == null || "".equals(strTransactedSession) || !strTransactedSession.equals("true")) { transactedSession = false; } else if ("true".equals(strTransactedSession)) { transactedSession = true; logger.warn( "Usage of transport.jms.SessionTransacted property is deprecated. Please use SESSION_TRANSACTED " + "acknowledge mode to create a transacted session"); } String strSessionAck = properties.getProperty(JMSConstants.SESSION_ACK); if (null == strSessionAck) { sessionAckMode = 1; } else if (strSessionAck.equals("AUTO_ACKNOWLEDGE")) { sessionAckMode = Session.AUTO_ACKNOWLEDGE; } else if (strSessionAck.equals("CLIENT_ACKNOWLEDGE")) { sessionAckMode = Session.CLIENT_ACKNOWLEDGE; } else if (strSessionAck.equals("DUPS_OK_ACKNOWLEDGE")) { sessionAckMode = Session.DUPS_OK_ACKNOWLEDGE; } else if (strSessionAck.equals("SESSION_TRANSACTED")) { sessionAckMode = Session.SESSION_TRANSACTED; transactedSession = true; } else { sessionAckMode = 1; } createConnectionFactory(); }