Java Code Examples for javax.jms.Session#AUTO_ACKNOWLEDGE
The following examples show how to use
javax.jms.Session#AUTO_ACKNOWLEDGE .
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: JMSProxy.java From flex-blazeds with Apache License 2.0 | 6 votes |
/** * Initialize with settings from the JMS adapter. * * @param settings JMS settings to use for initialization. */ public void initialize(JMSSettings settings) { String ackString = settings.getAcknowledgeMode(); if (ackString.equals(JMSConfigConstants.AUTO_ACKNOWLEDGE)) acknowledgeMode = Session.AUTO_ACKNOWLEDGE; else if (ackString.equals(JMSConfigConstants.CLIENT_ACKNOWLEDGE)) acknowledgeMode = Session.CLIENT_ACKNOWLEDGE; else if (ackString.equals(JMSConfigConstants.DUPS_OK_ACKNOWLEDGE)) acknowledgeMode = Session.DUPS_OK_ACKNOWLEDGE; connectionFactoryName = settings.getConnectionFactory(); String username = settings.getConnectionUsername(); String password = settings.getConnectionPassword(); if (username != null || password != null) { connectionCredentials = new ConnectionCredentials(username, password); } destinationJndiName = settings.getDestinationJNDIName(); initialContextEnvironment = settings.getInitialContextEnvironment(); }
Example 2
Source File: AbstractListenerContainerParser.java From spring-analysis-note with MIT License | 6 votes |
@Nullable 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 3
Source File: ActiveMQActivationSpec.java From activemq-artemis with Apache License 2.0 | 6 votes |
/** * Constructor */ public ActiveMQActivationSpec() { if (logger.isTraceEnabled()) { logger.trace("constructor()"); } ra = null; destination = null; destinationType = null; messageSelector = null; acknowledgeMode = Session.AUTO_ACKNOWLEDGE; subscriptionDurability = false; subscriptionName = null; user = null; password = null; maxSession = DEFAULT_MAX_SESSION; transactionTimeout = 0; }
Example 4
Source File: AbstractListenerContainerParser.java From java-technology-stack with MIT License | 6 votes |
@Nullable 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 5
Source File: JMSFacade.java From iaf with Apache License 2.0 | 6 votes |
/** * Convencience function to convert the numeric value of an (@link #setAckMode(int) acknowledgeMode} to a human-readable string. */ public static String getAcknowledgeModeAsString(int ackMode) { String ackString; if (Session.AUTO_ACKNOWLEDGE == ackMode) { ackString = "Auto"; } else if (Session.CLIENT_ACKNOWLEDGE == ackMode) { ackString = "Client"; } else if (Session.DUPS_OK_ACKNOWLEDGE == ackMode) { ackString = "Dups"; } else { ackString = "none"; } return ackString; }
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: ActiveMQConnectionForContextImpl.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override public JMSContext createContext(int sessionMode) { switch (sessionMode) { case Session.AUTO_ACKNOWLEDGE: case Session.CLIENT_ACKNOWLEDGE: case Session.DUPS_OK_ACKNOWLEDGE: case Session.SESSION_TRANSACTED: case ActiveMQJMSConstants.INDIVIDUAL_ACKNOWLEDGE: case ActiveMQJMSConstants.PRE_ACKNOWLEDGE: break; default: throw new JMSRuntimeException("Invalid ackmode: " + sessionMode); } refCounter.increment(); return new ActiveMQJMSContext(this, sessionMode, threadAwareContext); }
Example 8
Source File: JmsFactory.java From nifi with Apache License 2.0 | 5 votes |
public static Session createSession(final Connection connection, final String configuredAckMode, final boolean transacted) throws JMSException { final int ackMode; if (configuredAckMode == null) { ackMode = Session.AUTO_ACKNOWLEDGE; } else { ackMode = configuredAckMode.equalsIgnoreCase(ACK_MODE_AUTO) ? Session.AUTO_ACKNOWLEDGE : Session.CLIENT_ACKNOWLEDGE; } final Session session = connection.createSession(transacted, ackMode); return session; }
Example 9
Source File: ActiveMQRAConnectionRequestInfo.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * Constructor * * @param prop The resource adapter properties * @param type The connection type */ public ActiveMQRAConnectionRequestInfo(final ActiveMQRAProperties prop, final int type) { if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("constructor(" + prop + ")"); } userName = prop.getUserName(); password = prop.getPassword(); clientID = prop.getClientID(); this.type = type; transacted = true; acknowledgeMode = Session.AUTO_ACKNOWLEDGE; }
Example 10
Source File: ActiveMQRASessionFactoryImpl.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public JMSContext createContext(int sessionMode) { boolean inJtaTx = inJtaTransaction(); int sessionModeToUse; switch (sessionMode) { case Session.AUTO_ACKNOWLEDGE: case Session.DUPS_OK_ACKNOWLEDGE: case ActiveMQJMSConstants.INDIVIDUAL_ACKNOWLEDGE: case ActiveMQJMSConstants.PRE_ACKNOWLEDGE: sessionModeToUse = sessionMode; break; //these are prohibited in JEE unless not in a JTA tx where they should be ignored and auto_ack used case Session.CLIENT_ACKNOWLEDGE: if (!inJtaTx) { throw ActiveMQRABundle.BUNDLE.invalidSessionTransactedModeRuntime(); } sessionModeToUse = Session.AUTO_ACKNOWLEDGE; break; case Session.SESSION_TRANSACTED: if (!inJtaTx) { throw ActiveMQRABundle.BUNDLE.invalidClientAcknowledgeModeRuntime(); } sessionModeToUse = Session.AUTO_ACKNOWLEDGE; break; default: throw ActiveMQRABundle.BUNDLE.invalidAcknowledgeMode(sessionMode); } incrementRefCounter(); return new ActiveMQRAJMSContext(this, sessionModeToUse, threadAwareContext); }
Example 11
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 12
Source File: ActiveMQActivationValidationUtils.java From activemq-artemis with Apache License 2.0 | 5 votes |
public static int validateAcknowledgeMode(final String value) { if ("DUPS_OK_ACKNOWLEDGE".equalsIgnoreCase(value) || "Dups-ok-acknowledge".equalsIgnoreCase(value)) { return Session.DUPS_OK_ACKNOWLEDGE; } else if ("AUTO_ACKNOWLEDGE".equalsIgnoreCase(value) || "Auto-acknowledge".equalsIgnoreCase(value)) { return Session.AUTO_ACKNOWLEDGE; } else { throw new IllegalArgumentException(value); } }
Example 13
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(); }
Example 14
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 15
Source File: ActiveMqSender.java From tangyuan2 with GNU General Public License v3.0 | 4 votes |
private void sendQueueMessage(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.createQueue(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 queue: " + ((XCO) arg).toXMLString()); log.info("send message to queue[" + 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 16
Source File: TomEEXAConnectionFactory.java From tomee with Apache License 2.0 | 4 votes |
@Override public JMSContext createContext(final String userName, final String password) { return new JMSContextImpl(this, Session.AUTO_ACKNOWLEDGE, userName, password, true); }
Example 17
Source File: ActiveMQRAManagedConnection.java From activemq-artemis with Apache License 2.0 | 4 votes |
/** * Setup the connection. * * @throws ResourceException Thrown if a connection couldn't be created */ private void setup() throws ResourceException { if (logger.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("setup()"); } try { createCF(); boolean transacted = cri.isTransacted(); int acknowledgeMode = Session.AUTO_ACKNOWLEDGE; if (cri.getType() == ActiveMQRAConnectionFactory.TOPIC_CONNECTION) { if (userName != null && password != null) { connection = (ActiveMQXAConnection) connectionFactory.createXATopicConnection(userName, password); } else { connection = (ActiveMQXAConnection) connectionFactory.createXATopicConnection(); } connection.setExceptionListener(this); xaSession = connection.createXATopicSession(); nonXAsession = connection.createNonXATopicSession(transacted, acknowledgeMode); } else if (cri.getType() == ActiveMQRAConnectionFactory.QUEUE_CONNECTION) { if (userName != null && password != null) { connection = (ActiveMQXAConnection) connectionFactory.createXAQueueConnection(userName, password); } else { connection = (ActiveMQXAConnection) connectionFactory.createXAQueueConnection(); } connection.setExceptionListener(this); xaSession = connection.createXAQueueSession(); nonXAsession = connection.createNonXAQueueSession(transacted, acknowledgeMode); } else { if (userName != null && password != null) { connection = (ActiveMQXAConnection) connectionFactory.createXAConnection(userName, password); } else { connection = (ActiveMQXAConnection) connectionFactory.createXAConnection(); } connection.setExceptionListener(this); xaSession = connection.createXASession(); nonXAsession = connection.createNonXASession(transacted, acknowledgeMode); } } catch (JMSException je) { throw new ResourceException(je.getMessage(), je); } }
Example 18
Source File: WeEventTopicSession.java From WeEvent with Apache License 2.0 | 4 votes |
@Override public int getAcknowledgeMode() { return Session.AUTO_ACKNOWLEDGE; }
Example 19
Source File: ActiveMQResourceAdapter.java From activemq-artemis with Apache License 2.0 | 4 votes |
public ClientSession createSession(final ClientSessionFactory parameterFactory, final int ackMode, final String user, final String pass, final Boolean preAck, final Integer dupsOkBatchSize, final Integer transactionBatchSize, final boolean deliveryTransacted, final boolean useLocalTx, final Integer txTimeout) throws Exception { ClientSession result; // if we are CMP or BMP using local tx we ignore the ack mode as we are transactional if (deliveryTransacted || useLocalTx) { // JBPAPP-8845 // If transacted we need to send the ack flush as soon as possible // as if any transaction times out, we need the ack on the server already if (useLocalTx) { result = parameterFactory.createSession(user, pass, false, false, false, false, 0); } else { result = parameterFactory.createSession(user, pass, true, false, false, false, 0); } } else { if (preAck != null && preAck) { result = parameterFactory.createSession(user, pass, false, true, true, true, -1); } else { // only auto ack and dups ok are supported switch (ackMode) { case Session.AUTO_ACKNOWLEDGE: result = parameterFactory.createSession(user, pass, false, true, true, false, 0); break; case Session.DUPS_OK_ACKNOWLEDGE: int actDupsOkBatchSize = dupsOkBatchSize != null ? dupsOkBatchSize : ActiveMQClient.DEFAULT_ACK_BATCH_SIZE; result = parameterFactory.createSession(user, pass, false, true, true, false, actDupsOkBatchSize); break; default: throw new IllegalArgumentException("Invalid ackmode: " + ackMode); } } } ActiveMQRALogger.LOGGER.debug("Using queue connection " + result); return result; }
Example 20
Source File: JMSProxy.java From flex-blazeds with Apache License 2.0 | 3 votes |
/** * Sets the acknowledge mode used by the <code>JMSProxy</code>. Valid values * are javax.jms.Session.AUTO_ACKNOWLEDGE, javax.jms.Session.CLIENT_ACKNOWLEDGE, * javax.jms.Session.DUPS_OK_ACNOWLEDGE. This property is optional and * defaults to javax.jms.Session.AUTO_ACKNOWLEDGE. * * @param acknowledgeMode An int representing the acknowledge mode used. */ public void setAcknowledgeMode(int acknowledgeMode) { if (acknowledgeMode == Session.AUTO_ACKNOWLEDGE || acknowledgeMode == Session.CLIENT_ACKNOWLEDGE || acknowledgeMode == Session.DUPS_OK_ACKNOWLEDGE) this.acknowledgeMode = acknowledgeMode; }