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.apache.activemq.artemis.tests.integration.persistence.metrics.JournalPendingMessageTest.java
@Test public void testQueueLargeMessageSize() throws Exception { ActiveMQConnectionFactory acf = (ActiveMQConnectionFactory) cf; acf.setMinLargeMessageSize(1000);/*from w ww .j ava2s . c o m*/ Connection connection = cf.createConnection(); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); String testText = StringUtils.repeat("t", 5000); ActiveMQTextMessage message = (ActiveMQTextMessage) session.createTextMessage(testText); session.createProducer(session.createQueue(defaultQueueName)).send(message); verifyPendingStats(defaultQueueName, 1, message.getCoreMessage().getPersistentSize()); verifyPendingDurableStats(defaultQueueName, 1, message.getCoreMessage().getPersistentSize()); connection.close(); this.killServer(); this.restartServer(); verifyPendingStats(defaultQueueName, 1, message.getCoreMessage().getPersistentSize()); verifyPendingDurableStats(defaultQueueName, 1, message.getCoreMessage().getPersistentSize()); }
From source file:com.opengamma.examples.analyticservice.ExampleAnalyticServiceUsage.java
private void pushTrade(String securityId, Connection connection, String destinationName, JmsConnector jmsConnector, JmsByteArrayMessageDispatcher jmsDispatcher) { String providerId = generateTrade(securityId, destinationName, jmsConnector); String topicStr = PREFIX + SEPARATOR + providerId + SEPARATOR + "Default" + SEPARATOR + ValueRequirementNames.FAIR_VALUE; try {//from w w w.jav a2s . co m Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Topic topic = session.createTopic(topicStr); final MessageConsumer messageConsumer = session.createConsumer(topic); messageConsumer.setMessageListener(jmsDispatcher); } catch (JMSException e) { throw new OpenGammaRuntimeException("Failed to create subscription to JMS topics ", e); } }
From source file:eu.learnpad.simulator.mon.manager.ResponseDispatcher.java
public static void sendScoresEvaluation(HashMap<ScoreType, Float> scores, String destination, String channel, String userid, String simulationSessionID) { try {//from www .j av a2s. c o m publicSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); connectionTopic = publishSession.createTopic(channel); tPub = publishSession.createPublisher(connectionTopic); ObjectMessage sendMessage = publishSession.createObjectMessage(); sendMessage.setObject((Serializable) scores); sendMessage.setStringProperty("DESTINATION", destination); sendMessage.setStringProperty("USERID", userid); sendMessage.setBooleanProperty("ISASCORE", true); sendMessage.setStringProperty("SIMSESSIONID", simulationSessionID); tPub.publish(sendMessage); } catch (JMSException e) { DebugMessages.println(TimeStamp.getCurrentTime(), ResponseDispatcher.class.getSimpleName(), "Exception during sendScoresEvaluation method execution"); } }
From source file:com.mirth.connect.connectors.jms.JmsDispatcherTests.java
@BeforeClass public static void beforeClass() throws Exception { JmsDispatcherProperties properties = getInitialProperties(); if (properties.isUseJndi()) { connectionFactory = lookupConnectionFactoryWithJndi(properties); } else {//from www . jav a2s . c o m String className = properties.getConnectionFactoryClass(); connectionFactory = (ConnectionFactory) Class.forName(className).newInstance(); } BeanUtils.populate(connectionFactory, properties.getConnectionProperties()); Connection connection = connectionFactory.createConnection(properties.getUsername(), properties.getPassword()); connection.start(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); }
From source file:org.easybatch.jms.JmsIntegrationTest.java
@Test public void testJmsRecordWriter() throws Exception { Context jndiContext = getJndiContext(); Queue queue = (Queue) jndiContext.lookup("q"); QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) jndiContext .lookup("QueueConnectionFactory"); QueueConnection queueConnection = queueConnectionFactory.createQueueConnection(); QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); queueConnection.start();/*from w ww . j a v a 2s .co m*/ String dataSource = "foo" + LINE_SEPARATOR + "bar"; aNewJob().reader(new StringRecordReader(dataSource)).processor(new JmsMessageTransformer(queueSession)) .writer(new JmsQueueRecordWriter(queueConnectionFactory, queue)).call(); // Assert that queue contains 2 messages: "foo" and "bar" QueueBrowser queueBrowser = queueSession.createBrowser(queue); Enumeration enumeration = queueBrowser.getEnumeration(); assertThat(enumeration.hasMoreElements()).isTrue(); TextMessage message1 = (TextMessage) enumeration.nextElement(); assertThat(message1.getText()).isEqualTo("foo"); assertThat(enumeration.hasMoreElements()).isTrue(); TextMessage message2 = (TextMessage) enumeration.nextElement(); assertThat(message2.getText()).isEqualTo("bar"); assertThat(enumeration.hasMoreElements()).isFalse(); queueSession.close(); queueConnection.close(); }
From source file:org.apache.falcon.messaging.ProcessProducerTest.java
private void consumer() throws JMSException { ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(BROKER_URL); Connection connection = connectionFactory.createConnection(); connection.start();/*from ww w . j a v a 2s . c om*/ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination destination = session.createTopic(getTopicName()); MessageConsumer consumer = session.createConsumer(destination); latch.countDown(); for (int index = 0; index < outputFeedNames.length; ++index) { MapMessage m = (MapMessage) consumer.receive(); System.out.println("Consumed: " + m.toString()); assertMessage(m); Assert.assertEquals(m.getString(WorkflowExecutionArgs.OUTPUT_FEED_NAMES.getName()), outputFeedNames[index]); Assert.assertEquals(m.getString(WorkflowExecutionArgs.OUTPUT_FEED_PATHS.getName()), outputFeedPaths[index]); } connection.close(); }
From source file:org.wso2.andes.systest.GlobalQueuesTest.java
/** * Test that setting depth has an effect on durable consumer topics * * Ensure we set the delete-persistent option * * Sets the message size for the test// w ww. j a v a2 s . c om * Sets the depth to be 9 * the depth * Ensure that sending 10 messages causes the disconnection * * @throws Exception */ public void testTopicDurableConsumerMessageSize() throws Exception { MAX_QUEUE_MESSAGE_COUNT = 10; setConfig("depth", String.valueOf(MESSAGE_SIZE * 9), true); //Start the broker startBroker(); setMessageSize(MESSAGE_SIZE); topicConsumer(Session.AUTO_ACKNOWLEDGE, true); }
From source file:nl.nn.adapterframework.extensions.tibco.TibcoUtils.java
public static long getQueueMessageCount(String provUrl, String authAlias, String userName, String password, String queueName, String messageSelector) throws JMSException { Connection connection = null; Session jSession = null;/*ww w . jav a2 s . c o m*/ try { connection = getConnection(provUrl, authAlias, userName, password); jSession = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE); return getQueueMessageCount(jSession, queueName, messageSelector); } finally { if (connection != null) { try { connection.close(); } catch (JMSException e) { log.warn("Exception on closing connection", e); } } } }
From source file:com.fusesource.forge.jmstest.tests.AsyncProducer.java
public void run() { try {//from www .j av a 2s.c om Connection conn = getConnection(); Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); if (isExpectReply()) { Destination replyTo = getDestinationProvider().getDestination(session, getReplyDestination()); MessageConsumer consumer = session.createConsumer(replyTo); consumer.setMessageListener(this); } Destination dest = getDestinationProvider().getDestination(session, getDestinationName()); MessageProducer producer = session.createProducer(dest); producer.setDeliveryMode(getDeliveryMode().getCode()); getConnection().start(); LOG.info(">>Starting Message send loop"); while (!done.get()) { try { locallySent++; Destination replyDest = null; Message msg = getMessageFactory().createMessage(session); if (getMsgGroup() != null) { LOG.debug("Setting message group to : " + getMsgGroup()); msg.setStringProperty("JMSXGroupID", getMsgGroup()); if (getMessagesToSend() > 0) { if (locallySent == getMessagesToSend()) { LOG.debug("Closing message group: " + getMsgGroup()); msg.setIntProperty("JMSXGroupSeq", 0); } } } msg.setLongProperty("MsgNr", locallySent); if (isExpectReply()) { corrId = getReplyDestination() + "Seq-" + locallySent; msg.setStringProperty("JMSCorrelationID", corrId); replyDest = getDestinationProvider().getDestination(session, getReplyDestination()); msg.setJMSReplyTo(replyDest); receivedResponse = false; } long sendTime = System.currentTimeMillis(); producer.send(msg, deliveryMode.getCode(), 4, ttl); if (sent != null) { sent.incrementAndGet(); } done.set((getMessagesToSend() > 0) && ((locallySent) == getMessagesToSend())); if (isExpectReply()) { try { LOG.debug("Waiting for response ..."); synchronized (corrId) { try { if (getReplyTimeOut() > 0) { corrId.wait(getReplyTimeOut()); } else { corrId.wait(); } } catch (InterruptedException ie) { } if (receivedResponse) { long duration = System.currentTimeMillis() - sendTime; LOG.debug("Got response from peer in " + duration + " ms"); } else { LOG.error("Response not received within time frame..."); if (timeOuts != null) { timeOuts.incrementAndGet(); } } } } catch (Exception e) { if (exceptions != null) { exceptions.incrementAndGet(); } } } if (sleep > 0L) { try { Thread.sleep(sleep); } catch (InterruptedException ie) { } } } catch (JMSException e) { if (exceptions != null) { exceptions.incrementAndGet(); } } } } catch (Exception e) { } finally { try { closeConnection(); } catch (Throwable e) { } } LOG.info(">>MessageSender done...(" + sent + ")"); }
From source file:org.dawnsci.commandserver.ui.view.ConsumerView.java
/** * Listens to a topic/* w ww . j a va2 s. c o m*/ */ private void createTopicListener(final URI uri) throws Exception { // Use job because connection might timeout. final Job topicJob = new Job("Create topic listener") { @Override protected IStatus run(IProgressMonitor monitor) { try { ConnectionFactory connectionFactory = ConnectionFactoryFacade.createConnectionFactory(uri); topicConnection = connectionFactory.createConnection(); topicConnection.start(); Session session = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); final Topic topic = session.createTopic(Constants.ALIVE_TOPIC); final MessageConsumer consumer = session.createConsumer(topic); final ObjectMapper mapper = new ObjectMapper(); MessageListener listener = new MessageListener() { public void onMessage(Message message) { try { if (message instanceof TextMessage) { TextMessage t = (TextMessage) message; final ConsumerBean bean = mapper.readValue(t.getText(), ConsumerBean.class); bean.setLastAlive(System.currentTimeMillis()); consumers.put(bean.getConsumerId(), bean); } } catch (Exception e) { logger.error("Updating changed bean from topic", e); } } }; consumer.setMessageListener(listener); return Status.OK_STATUS; } catch (Exception ne) { logger.error("Cannot listen to topic changes because command server is not there", ne); return Status.CANCEL_STATUS; } } }; topicJob.setPriority(Job.INTERACTIVE); topicJob.setSystem(true); topicJob.setUser(false); topicJob.schedule(); }