Java Code Examples for javax.jms.DeliveryMode#NON_PERSISTENT
The following examples show how to use
javax.jms.DeliveryMode#NON_PERSISTENT .
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: MessagingMessageListenerAdapterTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void replyWithFullQoS() throws JMSException { Session session = mock(Session.class); Queue replyDestination = mock(Queue.class); given(session.createQueue("queueOut")).willReturn(replyDestination); MessageProducer messageProducer = mock(MessageProducer.class); TextMessage responseMessage = mock(TextMessage.class); given(session.createTextMessage("Response")).willReturn(responseMessage); given(session.createProducer(replyDestination)).willReturn(messageProducer); MessagingMessageListenerAdapter listener = getPayloadInstance("Response", "replyPayloadToQueue", Message.class); QosSettings settings = new QosSettings(DeliveryMode.NON_PERSISTENT, 6, 6000); listener.setResponseQosSettings(settings); listener.onMessage(mock(javax.jms.Message.class), session); verify(session).createQueue("queueOut"); verify(session).createTextMessage("Response"); verify(messageProducer).send(responseMessage, DeliveryMode.NON_PERSISTENT, 6, 6000); verify(messageProducer).close(); }
Example 2
Source File: MockJMSProducer.java From pooled-jms with Apache License 2.0 | 5 votes |
@Override public JMSProducer setDeliveryMode(int deliveryMode) { switch (deliveryMode) { case DeliveryMode.PERSISTENT: case DeliveryMode.NON_PERSISTENT: this.deliveryMode = deliveryMode; return this; default: throw new JMSRuntimeException(String.format("Invalid DeliveryMode specified: %d", deliveryMode)); } }
Example 3
Source File: JmsQueueCompositeSendReceiveTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * Sets a test to have a queue destination and non-persistent delivery mode. * * @see junit.framework.TestCase#setUp() */ @Override protected void setUp() throws Exception { topic = false; deliveryMode = DeliveryMode.NON_PERSISTENT; super.setUp(); ActiveMQDestination dest1 = (ActiveMQDestination) session.createQueue("FOO.BAR.HUMBUG2"); ActiveMQDestination dest2 = (ActiveMQDestination) session.createQueue("TEST"); ArtemisBrokerHelper.makeSureDestinationExists(dest1); ArtemisBrokerHelper.makeSureDestinationExists(dest2); }
Example 4
Source File: ServerJMSMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public final void setJMSDeliveryMode(int deliveryMode) throws JMSException { if (deliveryMode == DeliveryMode.PERSISTENT) { message.setDurable(true); } else if (deliveryMode == DeliveryMode.NON_PERSISTENT) { message.setDurable(false); } else { throw new JMSException("Invalid mode " + deliveryMode); } }
Example 5
Source File: JmsTopicCompositeSendReceiveTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * Sets a test to have a queue destination and non-persistent delivery mode. * * @see junit.framework.TestCase#setUp() */ @Override protected void setUp() throws Exception { deliveryMode = DeliveryMode.NON_PERSISTENT; super.setUp(); consumerDestination2 = consumeSession.createTopic("FOO.BAR.HUMBUG2"); LOG.info("Created consumer destination: " + consumerDestination2 + " of type: " + consumerDestination2.getClass()); if (durable) { LOG.info("Creating durable consumer"); consumer2 = consumeSession.createDurableSubscriber((Topic) consumerDestination2, getName()); } else { consumer2 = consumeSession.createConsumer(consumerDestination2); } }
Example 6
Source File: DeadLetterTestSupport.java From activemq-artemis with Apache License 2.0 | 5 votes |
public void testTransientQueueMessage() throws Exception { super.topic = false; deliveryMode = DeliveryMode.NON_PERSISTENT; durableSubscriber = false; doTest(); validateConsumerPrefetch(this.getDestinationString(), 0); }
Example 7
Source File: ActiveMQMessageProducer.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public void setDeliveryMode(final int deliveryMode) throws JMSException { checkClosed(); if (deliveryMode != DeliveryMode.NON_PERSISTENT && deliveryMode != DeliveryMode.PERSISTENT) { throw ActiveMQJMSClientBundle.BUNDLE.illegalDeliveryMode(deliveryMode); } defaultDeliveryMode = deliveryMode; }
Example 8
Source File: MockJMSMessage.java From pooled-jms with Apache License 2.0 | 5 votes |
@Override public void setJMSDeliveryMode(int deliveryMode) throws JMSException { switch (deliveryMode) { case DeliveryMode.PERSISTENT: persistent = true; break; case DeliveryMode.NON_PERSISTENT: persistent = false; break; default: throw new JMSException(String.format("Invalid DeliveryMode specific: %d", deliveryMode)); } }
Example 9
Source File: ActiveMQMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public void setJMSDeliveryMode(final int deliveryMode) throws JMSException { if (deliveryMode == DeliveryMode.PERSISTENT) { message.setDurable(true); } else if (deliveryMode == DeliveryMode.NON_PERSISTENT) { message.setDurable(false); } else { throw ActiveMQJMSClientBundle.BUNDLE.illegalDeliveryMode(deliveryMode); } }
Example 10
Source File: JmsQueueWildcardSendReceiveTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * Sets a test to have a queue destination and non-persistent delivery mode. * * @see junit.framework.TestCase#setUp() */ @Override protected void setUp() throws Exception { topic = false; deliveryMode = DeliveryMode.NON_PERSISTENT; super.setUp(); }
Example 11
Source File: MockJMSMessage.java From pooled-jms with Apache License 2.0 | 4 votes |
@Override public int getJMSDeliveryMode() throws JMSException { return persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT; }
Example 12
Source File: ServerJMSMessage.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Override public final int getJMSDeliveryMode() throws JMSException { return message.isDurable() ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT; }
Example 13
Source File: PublishOnTemporaryQueueConsumedMessageTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Override protected void setUp() throws Exception { topic = false; deliveryMode = DeliveryMode.NON_PERSISTENT; super.setUp(); }
Example 14
Source File: ProducerConfigTest.java From qpid-broker-j with Apache License 2.0 | 4 votes |
@Test public void testCreateProducerCommand() { String destination = "url:/destination"; int messageSize = 1000; int numberOfMessages = 10; int priority = 4; long timeToLive = 10000; int batchSize = 5; long interval = 60; long maximumDuration = 70; long startDelay = 80; String providerName = "testProvider1"; ProducerConfig producerConfig = new ProducerConfig( "producer1", destination, numberOfMessages, batchSize, maximumDuration, DeliveryMode.NON_PERSISTENT, messageSize, priority, timeToLive, interval, providerName); CreateProducerCommand command = producerConfig.createCommand("session1"); assertEquals("session1", command.getSessionName()); assertEquals("producer1", command.getParticipantName()); assertEquals(destination, command.getDestinationName()); assertEquals((long) numberOfMessages, command.getNumberOfMessages()); assertEquals((long) batchSize, (long) command.getBatchSize()); assertEquals(maximumDuration, command.getMaximumDuration()); assertEquals((long) DeliveryMode.NON_PERSISTENT, (long) command.getDeliveryMode()); assertEquals((long) messageSize, (long) command.getMessageSize()); assertEquals((long) priority, (long) command.getPriority()); assertEquals(timeToLive, command.getTimeToLive()); assertEquals(interval, command.getInterval()); assertEquals(providerName, command.getMessageProviderName()); }
Example 15
Source File: BrokerTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
public void testQueueBrowserWith2ConsumersBrowseFirst() throws Exception { ActiveMQDestination destination = new ActiveMQQueue("TEST"); deliveryMode = DeliveryMode.NON_PERSISTENT; // Setup a second connection with a queue browser. StubConnection connection2 = createConnection(); ConnectionInfo connectionInfo2 = createConnectionInfo(); SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2); ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination); consumerInfo2.setPrefetchSize(10); consumerInfo2.setBrowser(true); connection2.send(connectionInfo2); connection2.send(sessionInfo2); connection2.request(consumerInfo2); // Setup a first connection StubConnection connection1 = createConnection(); ConnectionInfo connectionInfo1 = createConnectionInfo(); SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1); ProducerInfo producerInfo = createProducerInfo(sessionInfo1); connection1.send(connectionInfo1); connection1.send(sessionInfo1); connection1.send(producerInfo); ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination); consumerInfo1.setPrefetchSize(10); connection1.request(consumerInfo1); // Send the messages connection1.send(createMessage(producerInfo, destination, deliveryMode)); connection1.send(createMessage(producerInfo, destination, deliveryMode)); connection1.send(createMessage(producerInfo, destination, deliveryMode)); //as the messages are sent async - need to synchronize the last //one to ensure they arrive in the order we want connection1.request(createMessage(producerInfo, destination, deliveryMode)); List<Message> messages = new ArrayList<>(); for (int i = 0; i < 4; i++) { Message m1 = receiveMessage(connection1); assertNotNull("m1 is null for index: " + i, m1); messages.add(m1); } // no messages present in queue browser as there were no messages when it // was created assertNoMessagesLeft(connection1); assertNoMessagesLeft(connection2); }
Example 16
Source File: AMQPClient.java From amazon-mq-workshop with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { CommandLine cmd = parseAndValidateCommandLineArguments(args); final WrapInt count = new WrapInt(); final long ds = System.currentTimeMillis(); final int interval = Integer.parseInt(cmd.getOptionValue("interval", "1000")); String name = cmd.getOptionValue("name", UUID.randomUUID().toString()); int deliveryMode = cmd.hasOption("notPersistent") ? DeliveryMode.NON_PERSISTENT : DeliveryMode.PERSISTENT; registerShutdownHook(count, ds, interval); try { String user = null; String password = null; String secrets = null; if (cmd.hasOption("user") && cmd.hasOption("password")) { user = cmd.getOptionValue("user"); password = cmd.getOptionValue("password"); } else { secrets = getUserPassword("MQBrokerUserPassword"); if (secrets!=null && !secrets.isEmpty()) { user = secrets.split(",")[0]; password = secrets.split(",")[1]; } } JmsConnectionFactory connFact = new JmsConnectionFactory(user, password, cmd.getOptionValue("url")); JmsConnection conn = (JmsConnection) connFact.createConnection(); conn.setClientID("AmazonMQWorkshop-" + System.currentTimeMillis()); conn.start(); Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE); if (cmd.getOptionValue("mode").contentEquals("sender")) { if (cmd.getOptionValue("type").contentEquals("queue")) { MessageProducer queueMessageProducer = session.createProducer(session.createQueue(cmd.getOptionValue("type") + "://" + cmd.getOptionValue("destination"))); sendMessages(session, queueMessageProducer, name, interval, deliveryMode, count); } else { MessageProducer topicMessageProducer = session.createProducer(session.createTopic(cmd.getOptionValue("type") + "://" + cmd.getOptionValue("destination"))); sendMessages(session, topicMessageProducer, name, interval, deliveryMode, count); } } else { if (cmd.getOptionValue("type").contentEquals("queue")) { MessageConsumer queueConsumer = session.createConsumer(session.createQueue(cmd.getOptionValue("destination"))); receiveMessages(session, queueConsumer); } else { MessageConsumer topicConsumer = session.createConsumer(session.createTopic(cmd.getOptionValue("destination"))); receiveMessages(session, topicConsumer); } } } catch (javax.jms.JMSSecurityException ex) { System.out.println(String.format("Error: %s", ex.getMessage())); System.exit(1); } }
Example 17
Source File: MessageRenderer.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
/** Render a {@link javax.jms.Message}. */ public String doRender(Object o) { if(o instanceof Message) { StringBuffer sbuf = new StringBuffer(); Message m = (Message) o; try { sbuf.append("DeliveryMode="); switch(m.getJMSDeliveryMode()) { case DeliveryMode.NON_PERSISTENT : sbuf.append("NON_PERSISTENT"); break; case DeliveryMode.PERSISTENT : sbuf.append("PERSISTENT"); break; default: sbuf.append("UNKNOWN"); } sbuf.append(", CorrelationID="); sbuf.append(m.getJMSCorrelationID()); sbuf.append(", Destination="); sbuf.append(m.getJMSDestination()); sbuf.append(", Expiration="); sbuf.append(m.getJMSExpiration()); sbuf.append(", MessageID="); sbuf.append(m.getJMSMessageID()); sbuf.append(", Priority="); sbuf.append(m.getJMSPriority()); sbuf.append(", Redelivered="); sbuf.append(m.getJMSRedelivered()); sbuf.append(", ReplyTo="); sbuf.append(m.getJMSReplyTo()); sbuf.append(", Timestamp="); sbuf.append(m.getJMSTimestamp()); sbuf.append(", Type="); sbuf.append(m.getJMSType()); //Enumeration enum = m.getPropertyNames(); //while(enum.hasMoreElements()) { // String key = (String) enum.nextElement(); // sbuf.append("; "+key+"="); // sbuf.append(m.getStringProperty(key)); //} } catch(JMSException e) { LogLog.error("Could not parse Message.", e); } return sbuf.toString(); } else { return o.toString(); } }
Example 18
Source File: MessageRenderer.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
/** * Render a {@link Message}. */ public String doRender(final Object o) { if (o instanceof Message) { final StringBuilder sbuf = new StringBuilder(100); final Message m = (Message) o; try { sbuf.append("DeliveryMode="); switch (m.getJMSDeliveryMode()) { case DeliveryMode.NON_PERSISTENT: sbuf.append("NON_PERSISTENT"); break; case DeliveryMode.PERSISTENT: sbuf.append("PERSISTENT"); break; default: sbuf.append("UNKNOWN"); } sbuf.append(", CorrelationID="); sbuf.append(m.getJMSCorrelationID()); sbuf.append(", Destination="); sbuf.append(m.getJMSDestination()); sbuf.append(", Expiration="); sbuf.append(m.getJMSExpiration()); sbuf.append(", MessageID="); sbuf.append(m.getJMSMessageID()); sbuf.append(", Priority="); sbuf.append(m.getJMSPriority()); sbuf.append(", Redelivered="); sbuf.append(m.getJMSRedelivered()); sbuf.append(", ReplyTo="); sbuf.append(m.getJMSReplyTo()); sbuf.append(", Timestamp="); sbuf.append(m.getJMSTimestamp()); sbuf.append(", Type="); sbuf.append(m.getJMSType()); //Enumeration enum = m.getPropertyNames(); //while(enum.hasMoreElements()) { // String key = (String) enum.nextElement(); // sbuf.append("; "+key+"="); // sbuf.append(m.getStringProperty(key)); //} } catch (final JMSException e) { LogLog.error("Could not parse Message.", e); } return sbuf.toString(); } else { return o.toString(); } }
Example 19
Source File: JmsTemplate.java From spring4-understanding with Apache License 2.0 | 2 votes |
/** * Set whether message delivery should be persistent or non-persistent, * specified as boolean value ("true" or "false"). This will set the delivery * mode accordingly, to either "PERSISTENT" (2) or "NON_PERSISTENT" (1). * <p>Default is "true" a.k.a. delivery mode "PERSISTENT". * @see #setDeliveryMode(int) * @see javax.jms.DeliveryMode#PERSISTENT * @see javax.jms.DeliveryMode#NON_PERSISTENT */ public void setDeliveryPersistent(boolean deliveryPersistent) { this.deliveryMode = (deliveryPersistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT); }
Example 20
Source File: JmsTemplate.java From java-technology-stack with MIT License | 2 votes |
/** * Set whether message delivery should be persistent or non-persistent, * specified as boolean value ("true" or "false"). This will set the delivery * mode accordingly, to either "PERSISTENT" (2) or "NON_PERSISTENT" (1). * <p>Default is "true" a.k.a. delivery mode "PERSISTENT". * @see #setDeliveryMode(int) * @see javax.jms.DeliveryMode#PERSISTENT * @see javax.jms.DeliveryMode#NON_PERSISTENT */ public void setDeliveryPersistent(boolean deliveryPersistent) { this.deliveryMode = (deliveryPersistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT); }