JMS transactions
In this section, let's see how we can include transactions in messaging. We shall first demonstrate messaging without transactions using a few scenarios. We shall first describe the scenarios and write a test case. Then, we shall develop an application around it. We shall demonstrate sending messages using the convertandsendmessage()
method.
- Scenario 1: This is a positive use case, which we have seen in previous sections as well.
@Test public void testCorrectMessage() throws InterruptedException { Order order = new Order(0, "notification to deliver correctly"); ordersender.convertAndSendMessage(QUEUE_INCOMING, order); Thread.sleep(6000); printResults(); assertEquals(1, getSavedOrders()); assertEquals(0, getMessagesInQueue(QUEUE_INCOMING)); assertEquals(0, getMessagesInQueue(QUEUE_DLQ)); }
- Scenario 2: Here, let's use a negative scenario. The message producer sends information to the queues and the consumer reads it, but an exception occurs...