Java Code Examples for javax.jms.Session#CLIENT_ACKNOWLEDGE
The following examples show how to use
javax.jms.Session#CLIENT_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: 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 2
Source File: JMSConsumer.java From flex-blazeds with Apache License 2.0 | 6 votes |
/** * Used internally to acknowledge the arrival of a message to the JMS server. * * @param message The JMS message to acknowledge. */ protected void acknowledgeMessage(Message message) { if (getAcknowledgeMode() == Session.CLIENT_ACKNOWLEDGE) { try { message.acknowledge(); } catch (JMSException e) { if (Log.isInfo()) Log.getLogger(JMSAdapter.LOG_CATEGORY).info("JMS consumer for JMS destination '" + destinationJndiName + "' received an error in message acknowledgement: " + e.getMessage()); } } }
Example 3
Source File: IfsaFacade.java From iaf with Apache License 2.0 | 6 votes |
public void setAcknowledgeMode(String acknowledgeMode) { if (acknowledgeMode.equalsIgnoreCase("auto") || acknowledgeMode.equalsIgnoreCase("AUTO_ACKNOWLEDGE")) { ackMode = Session.AUTO_ACKNOWLEDGE; } else if (acknowledgeMode.equalsIgnoreCase("dups") || acknowledgeMode.equalsIgnoreCase("DUPS_OK_ACKNOWLEDGE")) { ackMode = Session.DUPS_OK_ACKNOWLEDGE; } else if (acknowledgeMode.equalsIgnoreCase("client") || acknowledgeMode.equalsIgnoreCase("CLIENT_ACKNOWLEDGE")) { ackMode = Session.CLIENT_ACKNOWLEDGE; } else { // ignore all ack modes, to test no acking log.warn("["+name+"] invalid acknowledgemode:[" + acknowledgeMode + "] setting no acknowledge"); ackMode = -1; } }
Example 4
Source File: StandardJmsActivationSpecFactory.java From java-technology-stack 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 5
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 6
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 7
Source File: JMSFacade.java From iaf with Apache License 2.0 | 6 votes |
/** * String-version of {@link #setAckMode(int)} */ @IbisDoc({"", "auto_acknowledge"}) public void setAcknowledgeMode(String acknowledgeMode) { if (acknowledgeMode.equalsIgnoreCase("auto") || acknowledgeMode.equalsIgnoreCase("AUTO_ACKNOWLEDGE")) { ackMode = Session.AUTO_ACKNOWLEDGE; } else if (acknowledgeMode.equalsIgnoreCase("dups") || acknowledgeMode.equalsIgnoreCase("DUPS_OK_ACKNOWLEDGE")) { ackMode = Session.DUPS_OK_ACKNOWLEDGE; } else if (acknowledgeMode.equalsIgnoreCase("client") || acknowledgeMode.equalsIgnoreCase("CLIENT_ACKNOWLEDGE")) { ackMode = Session.CLIENT_ACKNOWLEDGE; } else { // ignore all ack modes, to test no acking log.warn("["+name+"] invalid acknowledgemode:[" + acknowledgeMode + "] setting no acknowledge"); ackMode = -1; } }
Example 8
Source File: ClientJmsDelegate.java From qpid-broker-j with Apache License 2.0 | 6 votes |
public void commitOrAcknowledgeMessageIfNecessary(final String sessionName, final Message message) { try { final Session session = _testSessions.get(sessionName); if (session.getTransacted()) { synchronized(session) { session.commit(); } } else if (message != null && session.getAcknowledgeMode() == Session.CLIENT_ACKNOWLEDGE) { message.acknowledge(); } } catch (final JMSException jmse) { throw new DistributedTestException("Unable to commit or acknowledge message on session: " + sessionName, jmse); } }
Example 9
Source File: AbstractJMSProvider.java From perf-harness with MIT License | 5 votes |
/** * Register our presence and look up any required parameters for this class. * * The current implementation does not fully differentiate between the * different modes it may be used in and will therefore allow many * combinations of arguments which are nonsensical (most of them are simply * ignored in the current configuration). * * @see Config#registerSelf(Class). */ public static void registerConfig() { // static validation of parameters Config.registerSelf( AbstractJMSProvider.class ); if ( ! Config.isInvalid() ) { int timeOut = Config.parms.getInt("to"); if ( timeOut<0 ) { Config.logger.log(Level.WARNING,"Time out (to={0}) must be at least 0", timeOut); } int am = Config.parms.getInt("am"); if ((am != Session.AUTO_ACKNOWLEDGE) && (am != Session.DUPS_OK_ACKNOWLEDGE) && (am != Session.CLIENT_ACKNOWLEDGE)) { Config.logger.log(Level.WARNING, "Acknowledgement (am={0}) must be one of \n{1} for Auto\n{2} for DupsOK\n{3} for Client\n", new Object[] {am, Session.AUTO_ACKNOWLEDGE, Session.DUPS_OK_ACKNOWLEDGE, Session.CLIENT_ACKNOWLEDGE} ); } if ( Config.parms.getString("pw").length()!=0 && Config.parms.getString("us").length()==0 ) { Config.logger.warning("Cannot specify -pw without -us"); } durable = Config.parms.getBoolean( "du" ); int commit = Config.parms.getInt("cc"); if ( commit<1 ) { Config.logger.log( Level.WARNING, "Commit count (cc={0}) must be greater than 0", commit); } /* * TODO: Java 8 supports target type inference, so when moving to Java8 can * change following line to: * Config.registerAnother( Config.parms.<JMSProvider>getClazz("pc") ); */ Config.registerAnother( Config.parms.getClazz("pc") ); } }
Example 10
Source File: JmsContext.java From qpid-jms with Apache License 2.0 | 5 votes |
@Override public void acknowledge() { if (getSessionMode() == Session.CLIENT_ACKNOWLEDGE) { try { getSession().acknowledge(ACK_TYPE.ACCEPTED); } catch (JMSException jmse) { throw JmsExceptionSupport.createRuntimeException(jmse); } } }
Example 11
Source File: JmsMessageConsumer.java From qpid-jms with Apache License 2.0 | 5 votes |
/** * Called from the session when a new Message has been dispatched to this Consumer * from the connection. * * @param envelope * the newly arrived message. */ @Override public void onInboundMessage(final JmsInboundMessageDispatch envelope) { envelope.setConsumerInfo(consumerInfo); lock.lock(); try { if (acknowledgementMode == Session.CLIENT_ACKNOWLEDGE) { envelope.getMessage().setAcknowledgeCallback(new JmsAcknowledgeCallback(session)); } else if (session.isIndividualAcknowledge()) { envelope.getMessage().setAcknowledgeCallback(new JmsAcknowledgeCallback(session, envelope)); } if (envelope.isEnqueueFirst()) { this.messageQueue.enqueueFirst(envelope); } else { this.messageQueue.enqueue(envelope); } if (session.isStarted() && messageQueue.isRunning()) { if (messageListener != null) { session.getDispatcherExecutor().execute(deliveryTask); } else if (availableListener != null) { session.getDispatcherExecutor().execute(new Runnable() { @Override public void run() { if (messageQueue.isRunning()) { availableListener.onMessageAvailable(JmsMessageConsumer.this); } } }); } } } finally { lock.unlock(); } }
Example 12
Source File: ConsumerTool.java From chipster with MIT License | 5 votes |
public void setAckMode(String ackMode) { if ("CLIENT_ACKNOWLEDGE".equals(ackMode)) { this.ackMode = Session.CLIENT_ACKNOWLEDGE; } 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; } }
Example 13
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 14
Source File: ActiveMqReceiver.java From tangyuan2 with GNU General Public License v3.0 | 5 votes |
private void processMessage(Message message) throws Throwable { if (null == message) { // log.error("message is null..."); return; } try { XCO xcoMessage = null; if (message instanceof TextMessage) { TextMessage textMessage = (TextMessage) message; String text = textMessage.getText(); xcoMessage = XCO.fromXML(text); } else { // TODO } log.info("received a message from " + typeStr + "[" + queue.getName() + "]: " + xcoMessage); boolean execResult = true; if (null != xcoMessage) { execResult = exec(service, xcoMessage, binding); } if (execResult && Session.SESSION_TRANSACTED == session.getAcknowledgeMode()) { session.commit(); } else if (execResult && Session.CLIENT_ACKNOWLEDGE == session.getAcknowledgeMode()) { message.acknowledge(); } if (!execResult && Session.SESSION_TRANSACTED == session.getAcknowledgeMode()) { session.rollback(); } } catch (Throwable e) { if (Session.SESSION_TRANSACTED == session.getAcknowledgeMode()) { session.rollback(); } throw e; } }
Example 15
Source File: SQSConnection.java From amazon-sqs-java-messaging-lib with Apache License 2.0 | 5 votes |
/** * Creates a <code>Session</code> * * @param transacted * Only false is supported. * @param acknowledgeMode * Legal values are <code>Session.AUTO_ACKNOWLEDGE</code>, * <code>Session.CLIENT_ACKNOWLEDGE</code>, * <code>Session.DUPS_OK_ACKNOWLEDGE</code>, and * <code>SQSSession.UNORDERED_ACKNOWLEDGE</code> * @return a new session. * @throws JMSException * If the QueueConnection object fails to create a session due * to some internal error or lack of support for the specific * transaction and acknowledge mode. */ @Override public Session createSession(boolean transacted, int acknowledgeMode) throws JMSException { checkClosed(); actionOnConnectionTaken = true; if (transacted || acknowledgeMode == Session.SESSION_TRANSACTED) throw new JMSException("SQSSession does not support transacted"); SQSSession sqsSession; if (acknowledgeMode == Session.AUTO_ACKNOWLEDGE) { sqsSession = new SQSSession(this, AcknowledgeMode.ACK_AUTO.withOriginalAcknowledgeMode(acknowledgeMode)); } else if (acknowledgeMode == Session.CLIENT_ACKNOWLEDGE || acknowledgeMode == Session.DUPS_OK_ACKNOWLEDGE) { sqsSession = new SQSSession(this, AcknowledgeMode.ACK_RANGE.withOriginalAcknowledgeMode(acknowledgeMode)); } else if (acknowledgeMode == SQSSession.UNORDERED_ACKNOWLEDGE) { sqsSession = new SQSSession(this, AcknowledgeMode.ACK_UNORDERED.withOriginalAcknowledgeMode(acknowledgeMode)); } else { LOG.error("Unrecognized acknowledgeMode. Cannot create Session."); throw new JMSException("Unrecognized acknowledgeMode. Cannot create Session."); } synchronized (stateLock) { checkClosing(); sessions.add(sqsSession); /** * Any new sessions created on a started connection should be * started on creation */ if (running) { sqsSession.start(); } } return sqsSession; }
Example 16
Source File: SimpleOpenWireTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testSendReceiveUsingTtl() throws Exception { String brokerUri = "failover://tcp://" + OWHOST + ":" + OWPORT + "?wireFormat.maxInactivityDuration=5000&wireFormat.maxInactivityDurationInitalDelay=1000"; ActiveMQConnectionFactory testFactory = new ActiveMQConnectionFactory(brokerUri); Connection sendConnection = testFactory.createConnection(); Connection receiveConnection = testFactory.createConnection(); try { final int nMsg = 10; final long delay = 2L; AsyncConsumer consumer = new AsyncConsumer(queueName, receiveConnection, Session.CLIENT_ACKNOWLEDGE, delay, nMsg); Session sendSession = sendConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = sendSession.createQueue(queueName); MessageProducer producer = sendSession.createProducer(queue); for (int i = 0; i < nMsg; i++) { producer.send(sendSession.createTextMessage("testXX" + i)); } consumer.waitFor(nMsg * delay * 2); } finally { sendConnection.close(); receiveConnection.close(); } }
Example 17
Source File: JmsFactory.java From localization_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 18
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 19
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; }
Example 20
Source File: JmsAccessor.java From java-technology-stack with MIT License | 2 votes |
/** * Determine whether the given Session is in client acknowledge mode. * <p>This implementation uses JMS 1.1 API. * @param session the JMS Session to check * @return whether the given Session is in client acknowledge mode * @throws javax.jms.JMSException if thrown by JMS API methods * @see javax.jms.Session#getAcknowledgeMode() * @see javax.jms.Session#CLIENT_ACKNOWLEDGE */ protected boolean isClientAcknowledge(Session session) throws JMSException { return (session.getAcknowledgeMode() == Session.CLIENT_ACKNOWLEDGE); }