Java Code Examples for javax.jms.MessageProducer#setDeliveryMode()

The following examples show how to use javax.jms.MessageProducer#setDeliveryMode() . 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: JMSClient.java    From camel-kafka-connector with Apache License 2.0 6 votes vote down vote up
/**
 * Sends data to a JMS queue or topic
 *
 * @param queue the queue or topic to send data to
 * @param data  the (string) data to send
 * @throws JMSException
 */
public void send(final String queue, final String data) throws JMSException {
    MessageProducer producer = null;

    try {
        producer = session.createProducer(createDestination(queue));

        producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
        producer.setTimeToLive(0);

        Message message = session.createTextMessage(data);

        producer.send(message);
    } finally {
        capturingClose(producer);
    }
}
 
Example 2
Source File: SimpleNetworkTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 60 * 1000)
public void testMessageCompression() throws Exception {

   ActiveMQConnection localAmqConnection = (ActiveMQConnection) localConnection;
   localAmqConnection.setUseCompression(true);

   MessageConsumer consumer1 = remoteSession.createConsumer(included);
   MessageProducer producer = localSession.createProducer(included);
   producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

   waitForConsumerRegistration(localBroker, 1, included);

   for (int i = 0; i < MESSAGE_COUNT; i++) {
      Message test = localSession.createTextMessage("test-" + i);
      producer.send(test);
      Message msg = consumer1.receive(3000);
      assertNotNull(msg);
      ActiveMQMessage amqMessage = (ActiveMQMessage) msg;
      assertTrue(amqMessage.isCompressed());
   }
   // ensure no more messages received
   assertNull(consumer1.receive(1000));
}
 
Example 3
Source File: PooledSessionExhaustionBlockTimeoutTest.java    From pooled-jms with Apache License 2.0 6 votes vote down vote up
public void sendMessages(ConnectionFactory connectionFactory) throws Exception {
    for (int i = 0; i < NUM_MESSAGES; i++) {
        Connection connection = connectionFactory.createConnection();
        try {
            connection.start();

            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            Destination destination = session.createQueue(QUEUE);
            MessageProducer producer = session.createProducer(destination);
            producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

            String msgTo = "hello";
            TextMessage message = session.createTextMessage(msgTo);
            producer.send(message);
        } finally {
            connection.close();
        }
        LOG.debug("sent " + i + " messages using " + connectionFactory.getClass());
    }
}
 
Example 4
Source File: OrderClient.java    From camelinaction with Apache License 2.0 6 votes vote down vote up
public void sendOrder(int customerId, Date date, String... itemIds) throws Exception {
    // format the JMS message from the input parameters
    String d = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(date);
    String body = customerId + "," + d;
    for (String id : itemIds) {
        body += "," + id;
    }

    // use JMS code to send the message (a bit ugly code but it works)
    Connection con = fac.createConnection();
    con.start();
    Session ses = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination dest = ses.createQueue("order");
    MessageProducer prod = ses.createProducer(dest);
    prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
    Message msg = ses.createTextMessage(body);
    prod.send(msg);
    prod.close();
    ses.close();
    con.close();
}
 
Example 5
Source File: JmsMessageProducerTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 20000)
public void testPersistentSendsAreMarkedPersistent() throws Exception {
    connection = createAmqpConnection();
    assertNotNull(connection);
    connection.start();

    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    assertNotNull(session);
    Queue queue = session.createQueue(name.getMethodName());
    MessageProducer producer = session.createProducer(queue);
    producer.setDeliveryMode(DeliveryMode.PERSISTENT);

    QueueViewMBean proxy = getProxyToQueue(name.getMethodName());
    assertEquals(0, proxy.getQueueSize());

    Message message = session.createMessage();
    producer.send(message);

    assertEquals(1, proxy.getQueueSize());

    MessageConsumer consumer = session.createConsumer(queue);
    message = consumer.receive(5000);
    assertNotNull(message);
    assertTrue(message.getJMSDeliveryMode() == DeliveryMode.PERSISTENT);
}
 
Example 6
Source File: QueueDuplicatesTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
   try {
      Session session = createSession(brokerConnection);
      Destination dest = session.createQueue(subject);
      MessageProducer producer = session.createProducer(dest);
      producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
      for (int i = 0; i < 20; i++) {
         String txt = "Text Message: " + i;
         TextMessage msg = session.createTextMessage(txt);
         producer.send(msg);
         LOG.info(formatter.format(new Date()) + " Sent ==> " + msg + " to " + subject);
         Thread.sleep(1000);
      }
      session.close();
   } catch (Exception e) {
      e.printStackTrace();
   }
}
 
Example 7
Source File: JMSUsecase1Test.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testSendReceiveTransacted() throws Exception {
   // Send a message to the broker.
   connection.start();
   Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
   ActiveMQDestination destination = createDestination(session, destinationType);
   MessageProducer producer = session.createProducer(destination);
   producer.setDeliveryMode(this.deliveryMode);
   MessageConsumer consumer = session.createConsumer(destination);
   producer.send(session.createTextMessage("test"));

   // Message should not be delivered until commit.
   assertNull(consumer.receiveNoWait());
   session.commit();

   // Make sure only 1 message was delivered.
   Message message = consumer.receive(1000);
   assertNotNull(message);
   assertFalse(message.getJMSRedelivered());
   assertNull(consumer.receiveNoWait());

   // Message should be redelivered is rollback is used.
   session.rollback();

   // Make sure only 1 message was delivered.
   message = consumer.receive(2000);
   assertNotNull(message);
   assertTrue(message.getJMSRedelivered());
   assertNull(consumer.receiveNoWait());

   // If we commit now, the message should not be redelivered.
   session.commit();
   assertNull(consumer.receiveNoWait());
}
 
Example 8
Source File: DurableSubscriptionTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testUnsubscribeDurableSubscription() throws Exception {
   Connection conn = null;

   try {
      conn = createConnection();
      conn.setClientID("ak47");

      Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      MessageConsumer cons = s.createDurableSubscriber(ActiveMQServerTestCase.topic1, "uzzi");
      MessageProducer prod = s.createProducer(ActiveMQServerTestCase.topic1);
      prod.setDeliveryMode(DeliveryMode.PERSISTENT);

      prod.send(s.createTextMessage("one"));

      cons.close();
      s.unsubscribe("uzzi");

      MessageConsumer ds = s.createDurableSubscriber(ActiveMQServerTestCase.topic1, "uzzi");
      conn.start();

      ProxyAssertSupport.assertNull(ds.receiveNoWait());

      ds.close();

      s.unsubscribe("uzzi");
   } finally {
      if (conn != null) {
         conn.close();
      }
   }
}
 
Example 9
Source File: AmqpLargeMessageTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public void doTestSendLargeMessage(int expectedSize) throws Exception {
   LOG.debug("doTestSendLargeMessage called with expectedSize " + expectedSize);
   byte[] payload = createLargePayload(expectedSize);
   assertEquals(expectedSize, payload.length);

   ConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:61616");
   try (Connection connection = factory.createConnection()) {

      long startTime = System.currentTimeMillis();
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Queue queue = session.createQueue(name.getMethodName());
      MessageProducer producer = session.createProducer(queue);
      BytesMessage message = session.createBytesMessage();
      message.writeBytes(payload);
      producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

      // Set this to non-default to get a Header in the encoded message.
      producer.setPriority(4);
      producer.send(message);
      long endTime = System.currentTimeMillis();

      LOG.debug("Returned from send after {} ms", endTime - startTime);
      startTime = System.currentTimeMillis();
      MessageConsumer consumer = session.createConsumer(queue);
      connection.start();

      LOG.debug("Calling receive");
      Message received = consumer.receive();
      assertNotNull(received);
      assertTrue(received instanceof BytesMessage);
      BytesMessage bytesMessage = (BytesMessage) received;
      assertNotNull(bytesMessage);
      endTime = System.currentTimeMillis();

      LOG.debug("Returned from receive after {} ms", endTime - startTime);
      byte[] bytesReceived = new byte[expectedSize];
      assertEquals(expectedSize, bytesMessage.readBytes(bytesReceived, expectedSize));
      assertTrue(Arrays.equals(payload, bytesReceived));
      connection.close();
   }
}
 
Example 10
Source File: MessagingAddressJMSTest.java    From enmasse with Apache License 2.0 4 votes vote down vote up
@Test
@Disabled("Not yet supported")
@DisplayName("testSharedDurableSubscription")
void testSharedDurableSubscription(JmsProvider jmsProvider) throws Exception {
    String topicAddress = "jmsTopicDurable";
    String subID = "sharedConsumerDurable123";
    MessagingAddress addressTopic = new MessagingAddressBuilder()
            .withNewMetadata()
            .withNamespace(tenant.getMetadata().getNamespace())
            .withName("jms-topic-durable")
            .endMetadata()
            .withNewSpec()
            .editOrNewTopic()
            .endTopic()
            .withAddress(topicAddress)
            .endSpec()
            .build();
    MessagingAddress addressSub1= new MessagingAddressBuilder()
            .withNewMetadata()
            .withNamespace(tenant.getMetadata().getNamespace())
            .withName("jms-topic-durable-sub")
            .endMetadata()
            .withNewSpec()
            .editOrNewSubscription()
            .withTopic(topicAddress)
            .endSubscription()
            .withAddress(subID)
            .endSpec()
            .build();
    resourceManager.createResource(addressTopic, addressSub1);

    Context context1 = createContext(jmsProvider, addressTopic);
    Connection connection1 = jmsProvider.createConnection(context1);
    Context context2 = createContext(jmsProvider, addressTopic);
    Connection connection2 = jmsProvider.createConnection(context2);
    connection1.start();
    connection2.start();

    Session session = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);

    Topic testTopic = (Topic) jmsProvider.getDestination(topicAddress);

    log.info("Creating subscriber 1");
    MessageConsumer subscriber1 = session.createSharedDurableConsumer(testTopic, subID);
    log.info("Creating subscriber 2");
    MessageConsumer subscriber2 = session2.createSharedDurableConsumer(testTopic, subID);
    log.info("Creating producer");
    MessageProducer messageProducer = session.createProducer(testTopic);
    messageProducer.setDeliveryMode(DeliveryMode.PERSISTENT);

    int count = 10;
    List<javax.jms.Message> listMsgs = jmsProvider.generateMessages(session, count);
    jmsProvider.sendMessages(messageProducer, listMsgs);
    log.info("messages sent");

    List<javax.jms.Message> recvd1 = jmsProvider.receiveMessages(subscriber1, count, 1);
    List<javax.jms.Message> recvd2 = jmsProvider.receiveMessages(subscriber2, count, 1);

    log.info(subID + " :messages received");

    assertThat("Wrong count of messages received: by both receivers",
            recvd1.size() + recvd2.size(), is(2 * count));

    subscriber1.close();
    subscriber2.close();
    session.unsubscribe(subID);
    session2.unsubscribe(subID);
    connection1.stop();
    connection2.stop();
    session.close();
    session2.close();
    connection1.close();
    connection2.close();
}
 
Example 11
Source File: JmsMultipleBrokersTestSupport.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public MessageProducer createProducer(Destination dest, Session sess) throws Exception {
   MessageProducer client = sess.createProducer(dest);
   client.setDeliveryMode(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
   return client;
}
 
Example 12
Source File: DurableSubscriptionTestSupport.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public void testIndividualAckWithDurableSubs() throws Exception {
   // Create the consumer.
   connection.start();

   Session session = connection.createSession(false, ActiveMQSession.INDIVIDUAL_ACKNOWLEDGE);
   Topic topic = session.createTopic("topic-" + getName());
   MessageConsumer consumer = session.createDurableSubscriber(topic, "sub1");
   // Drain any messages that may already be in the sub
   while (consumer.receive(1000) != null) {
   }
   consumer.close();

   MessageProducer producer = session.createProducer(topic);
   producer.setDeliveryMode(DeliveryMode.PERSISTENT);
   producer.send(session.createTextMessage("Message 1"));
   producer.send(session.createTextMessage("Message 2"));
   producer.send(session.createTextMessage("Message 3"));
   producer.close();

   connection.close();
   connection = createConnection();
   connection.start();

   session = connection.createSession(false, ActiveMQSession.INDIVIDUAL_ACKNOWLEDGE);
   consumer = session.createDurableSubscriber(topic, "sub1");

   Message message = null;
   for (int i = 0; i < 3; ++i) {
      message = consumer.receive(5000);
      assertNotNull(message);
      assertEquals("Message " + (i + 1), ((TextMessage) message).getText());
   }

   message.acknowledge();

   connection.close();
   connection = createConnection();
   connection.start();

   session = connection.createSession(false, ActiveMQSession.INDIVIDUAL_ACKNOWLEDGE);
   consumer = session.createDurableSubscriber(topic, "sub1");

   for (int i = 0; i < 2; ++i) {
      message = consumer.receive(5000);
      assertNotNull(message);
      assertEquals("Message " + (i + 1), ((TextMessage) message).getText());
   }
}
 
Example 13
Source File: DurableSubscriptionTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
/**
 * JMS 1.1 6.11.1: A client can change an existing durable subscription by creating a durable
 * TopicSubscriber with the same name and a new topic and/or message selector, or NoLocal
 * attribute. Changing a durable subscription is equivalent to deleting and recreating it.
 * <br>
 * Test with a different selector.
 */
@Test
public void testDurableSubscriptionDifferentSelector() throws Exception {
   Connection conn = null;

   try {
      conn = createConnection();

      conn.setClientID("brookeburke");

      Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      MessageProducer prod = s.createProducer(ActiveMQServerTestCase.topic1);
      prod.setDeliveryMode(DeliveryMode.PERSISTENT);

      MessageConsumer durable = s.createDurableSubscriber(ActiveMQServerTestCase.topic1, "monicabelucci", "color = 'red' AND shape = 'square'", false);

      TextMessage tm = s.createTextMessage("A red square message");
      tm.setStringProperty("color", "red");
      tm.setStringProperty("shape", "square");

      prod.send(tm);

      conn.start();

      TextMessage rm = (TextMessage) durable.receive(5000);
      ProxyAssertSupport.assertEquals("A red square message", rm.getText());

      tm = s.createTextMessage("Another red square message");
      tm.setStringProperty("color", "red");
      tm.setStringProperty("shape", "square");
      prod.send(tm);

      // TODO: when subscriptions/durable subscription will be registered as MBean, use the JMX
      // interface to make sure the 'another red square message' is maintained by the
      // durable subascription
      // http://jira.jboss.org/jira/browse/JBMESSAGING-217

      conn.close();

      conn = createConnection();

      conn.setClientID("brookeburke");

      s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

      // modify the selector
      durable = s.createDurableSubscriber(ActiveMQServerTestCase.topic1, "monicabelucci", "color = 'red'", false);

      conn.start();

      Message m = durable.receiveNoWait();

      // the durable subscription is destroyed and re-created. The red square message stored by
      // the previous durable subscription is lost and (hopefully) garbage collected.
      ProxyAssertSupport.assertNull(m);

      durable.close();

      s.unsubscribe("monicabelucci");
   } finally {
      if (conn != null) {
         conn.close();
      }
   }
}
 
Example 14
Source File: SelectorTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
/**
 * Test case for http://jira.jboss.org/jira/browse/JBMESSAGING-105
 * <br>
 * Two Messages are sent to a queue. There is one receiver on the queue. The receiver only
 * receives one of the messages due to a message selector only matching one of them. The receiver
 * is then closed. A new receiver is now attached to the queue. Redelivery of the remaining
 * message is now attempted. The message should be redelivered.
 */
@Test
public void testSelectiveClosingConsumer() throws Exception {
   Connection conn = null;

   try {
      conn = getConnectionFactory().createConnection();
      conn.start();

      Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      MessageProducer prod = session.createProducer(queue1);
      prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

      String selector = "color = 'red'";
      MessageConsumer redConsumer = session.createConsumer(queue1, selector);
      conn.start();

      Message redMessage = session.createMessage();
      redMessage.setStringProperty("color", "red");

      Message blueMessage = session.createMessage();
      blueMessage.setStringProperty("color", "blue");

      prod.send(redMessage);
      prod.send(blueMessage);

      log.debug("sent message");

      Message rec = redConsumer.receive();
      ProxyAssertSupport.assertEquals(redMessage.getJMSMessageID(), rec.getJMSMessageID());
      ProxyAssertSupport.assertEquals("red", rec.getStringProperty("color"));

      ProxyAssertSupport.assertNull(redConsumer.receiveNoWait());

      redConsumer.close();

      log.debug("closed first consumer");

      MessageConsumer universalConsumer = session.createConsumer(queue1);

      rec = universalConsumer.receive(2000);

      ProxyAssertSupport.assertEquals(rec.getJMSMessageID(), blueMessage.getJMSMessageID());
      ProxyAssertSupport.assertEquals("blue", rec.getStringProperty("color"));
   } finally {
      if (conn != null) {
         conn.close();
      }
   }
}
 
Example 15
Source File: DurableSubscriptionTestSupport.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
private MessageProducer createProducer(Session session, Destination queue) throws JMSException {
   MessageProducer producer = session.createProducer(queue);
   producer.setDeliveryMode(getDeliveryMode());
   return producer;
}
 
Example 16
Source File: DurableSubscriberWithNetworkRestartTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public void testSendOnAReceiveOnBWithTransportDisconnect() throws Exception {
   bridge(SPOKE, HUB);
   startAllBrokers();

   verifyDuplexBridgeMbean();

   // Setup connection
   URI hubURI = brokers.get(HUB).broker.getTransportConnectors().get(0).getPublishableConnectURI();
   URI spokeURI = brokers.get(SPOKE).broker.getTransportConnectors().get(0).getPublishableConnectURI();
   ActiveMQConnectionFactory facHub = new ActiveMQConnectionFactory(hubURI);
   ActiveMQConnectionFactory facSpoke = new ActiveMQConnectionFactory(spokeURI);
   Connection conHub = facHub.createConnection();
   Connection conSpoke = facSpoke.createConnection();
   conHub.setClientID("clientHUB");
   conSpoke.setClientID("clientSPOKE");
   conHub.start();
   conSpoke.start();
   Session sesHub = conHub.createSession(false, Session.AUTO_ACKNOWLEDGE);
   Session sesSpoke = conSpoke.createSession(false, Session.AUTO_ACKNOWLEDGE);

   ActiveMQTopic topic = new ActiveMQTopic("TEST.FOO");
   String consumerName = "consumerName";

   // Setup consumers
   MessageConsumer remoteConsumer = sesHub.createDurableSubscriber(topic, consumerName);
   sleep(1000);
   remoteConsumer.close();

   // Setup producer
   MessageProducer localProducer = sesSpoke.createProducer(topic);
   localProducer.setDeliveryMode(DeliveryMode.PERSISTENT);

   final String payloadString = new String(new byte[10 * 1024]);
   // Send messages
   for (int i = 0; i < MESSAGE_COUNT; i++) {
      Message test = sesSpoke.createTextMessage("test-" + i);
      test.setStringProperty("payload", payloadString);
      localProducer.send(test);
   }
   localProducer.close();

   final String options = "?persistent=true&useJmx=true&deleteAllMessagesOnStartup=false";
   for (int i = 0; i < 2; i++) {
      brokers.get(SPOKE).broker.stop();
      sleep(1000);
      createBroker(new URI("broker:(tcp://localhost:61616)/" + SPOKE + options));
      bridge(SPOKE, HUB);
      brokers.get(SPOKE).broker.start();
      LOG.info("restarted spoke..:" + i);

      assertTrue("got mbeans on restart", Wait.waitFor(new Wait.Condition() {
         @Override
         public boolean isSatisified() throws Exception {
            return countMbeans(brokers.get(HUB).broker, "networkBridge", 20000) == (dynamicOnly ? 1 : 2);
         }
      }));
   }
}
 
Example 17
Source File: PagingOrderTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testPagingOverCreatedDestinationQueues() throws Exception {

   Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);

   ActiveMQServer server = createServer(true, config, -1, -1, new HashMap<String, AddressSettings>());
   server.getAddressSettingsRepository().getMatch("#").setAddressFullMessagePolicy(AddressFullMessagePolicy.BLOCK);

   JMSServerManagerImpl jmsServer = new JMSServerManagerImpl(server);
   InVMNamingContext context = new InVMNamingContext();
   jmsServer.setRegistry(new JndiBindingRegistry(context));
   jmsServer.start();

   server.getActiveMQServerControl().addAddressSettings("Q1", "DLQ", "DLQ", -1, false, 5, 100 * 1024, 10 * 1024, 5, 5, 1, 1000, 0, false, "PAGE", -1, 10, "KILL", true, true, true, true);

   jmsServer.createQueue(true, "Q1", null, true, "/queue/Q1");

   ActiveMQJMSConnectionFactory cf = (ActiveMQJMSConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));

   conn = cf.createConnection();
   conn.setClientID("tst");
   Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
   javax.jms.Queue queue = (javax.jms.Queue) context.lookup("/queue/Q1");

   MessageProducer prod = sess.createProducer(queue);
   prod.setDeliveryMode(DeliveryMode.PERSISTENT);
   BytesMessage bmt = sess.createBytesMessage();

   bmt.writeBytes(new byte[1024]);

   for (int i = 0; i < 500; i++) {
      prod.send(bmt);
   }

   PagingStore store = server.getPagingManager().getPageStore(new SimpleString("Q1"));

   assertEquals(100 * 1024, store.getMaxSize());
   assertEquals(10 * 1024, store.getPageSizeBytes());
   assertEquals(AddressFullMessagePolicy.PAGE, store.getAddressFullMessagePolicy());

   jmsServer.stop();

   server = createServer(true, config, -1, -1, new HashMap<String, AddressSettings>());
   server.getAddressSettingsRepository().getMatch("#").setAddressFullMessagePolicy(AddressFullMessagePolicy.BLOCK);

   jmsServer = new JMSServerManagerImpl(server);
   context = new InVMNamingContext();
   jmsServer.setRegistry(new JndiBindingRegistry(context));
   jmsServer.start();

   AddressSettings settings = server.getAddressSettingsRepository().getMatch("Q1");

   assertEquals(100 * 1024, settings.getMaxSizeBytes());
   assertEquals(10 * 1024, settings.getPageSizeBytes());
   assertEquals(AddressFullMessagePolicy.PAGE, settings.getAddressFullMessagePolicy());

   store = server.getPagingManager().getPageStore(new SimpleString("Q1"));
   assertEquals(100 * 1024, store.getMaxSize());
   assertEquals(10 * 1024, store.getPageSizeBytes());
   assertEquals(AddressFullMessagePolicy.PAGE, store.getAddressFullMessagePolicy());
}
 
Example 18
Source File: AzureServiceBusEventsListnerTest.java    From oneops with Apache License 2.0 3 votes vote down vote up
private void sendMessageToServer() throws JMSException, IOException {

		QueueConnection queueConn = (QueueConnection) connectionFactory.createConnection();
		queueConn.start();

		QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);

		Destination destination = queueSession.createQueue(jmsQueue);

		MessageProducer queueSender = queueSession.createProducer(destination);
		queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
		Message message = queueSession.createTextMessage(createMessage());
		queueSender.send(message);

	}
 
Example 19
Source File: MessageConsumerTest.java    From activemq-artemis with Apache License 2.0 2 votes vote down vote up
/**
 * The simplest possible receive() test for a non-persistent message.
 */
@Test
public void testReceive() throws Exception {
   Connection producerConnection = null;

   Connection consumerConnection = null;

   try {
      producerConnection = createConnection();

      consumerConnection = createConnection();

      Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);

      Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);

      MessageProducer queueProducer = producerSession.createProducer(queue1);

      MessageConsumer queueConsumer = consumerSession.createConsumer(queue1);

      // start consumer connection before the message is submitted
      consumerConnection.start();

      TextMessage tm = producerSession.createTextMessage("someText");

      queueProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

      queueProducer.send(tm);

      TextMessage m = (TextMessage) queueConsumer.receive();

      ProxyAssertSupport.assertEquals(tm.getText(), m.getText());
   } finally {
      if (producerConnection != null) {
         producerConnection.close();
      }
      if (consumerConnection != null) {
         consumerConnection.close();
      }
   }

}
 
Example 20
Source File: MessageConsumerTest.java    From activemq-artemis with Apache License 2.0 2 votes vote down vote up
@Test
public void testAckAfterConsumerClosed() throws Exception {
   Connection connSend = null;
   Connection connReceive = null;

   try {
      connSend = createConnection();

      connSend.start();

      Session sessSend = connSend.createSession(true, Session.SESSION_TRANSACTED);

      MessageProducer prod = sessSend.createProducer(queue1);

      prod.setDeliveryMode(DeliveryMode.PERSISTENT);

      Message m = sessSend.createTextMessage("hello");

      prod.send(m);

      sessSend.commit();

      connReceive = createConnection();

      connReceive.start();

      Session sessReceive = connReceive.createSession(true, Session.SESSION_TRANSACTED);

      MessageConsumer cons = sessReceive.createConsumer(queue1);

      TextMessage m2 = (TextMessage) cons.receive(1500);

      ProxyAssertSupport.assertNotNull(m2);

      ProxyAssertSupport.assertEquals("hello", m2.getText());

      // It is legal to close the consumer before committing the tx which is when
      // the acks are sent
      cons.close();

      sessReceive.commit();

      connReceive.close();

      log.trace("Done test");

   } finally {
      if (connSend != null) {
         connSend.close();
      }
      if (connReceive != null) {
         connReceive.close();
      }
   }
}