Author: jmesnil
Date: 2009-12-04 11:10:51 -0500 (Fri, 04 Dec 2009)
New Revision: 8557
Modified:
trunk/examples/jms/non-transaction-failover/readme.html
trunk/examples/jms/non-transaction-failover/src/org/hornetq/jms/example/NonTransactionFailoverExample.java
Log:
updated non-transaction-failover example
Modified: trunk/examples/jms/non-transaction-failover/readme.html
===================================================================
--- trunk/examples/jms/non-transaction-failover/readme.html 2009-12-04 15:46:18 UTC (rev
8556)
+++ trunk/examples/jms/non-transaction-failover/readme.html 2009-12-04 16:10:51 UTC (rev
8557)
@@ -101,18 +101,9 @@
}
catch (JMSException e)
{
- System.out.println("Got exception while acknowledging message: "
+ e.getMessage());
- ...
+ System.err.println("Got exception while acknowledging message: "
+ e.getMessage());
}
</pre>
-
- <li>The client must cope with the failover and recreate the JMS
session</li>
- <pre class="prettyprint">
- session.close();
- session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- producer = session.createProducer(queue);
- consumer = session.createConsumer(queue);
- </pre>
<li>Consume again the second half of the messages againg. Note that they
are not considered as redelivered</li>
<pre class="prettyprint">
@@ -124,26 +115,6 @@
message0.acknowledge();
</pre>
- <li>Send some more messages</li>
- <pre class="prettyprint">
- for (int i = numMessages; i < numMessages * 2; i++)
- {
- TextMessage message = session.createTextMessage("This is text message
" + i);
- producer.send(message);
- System.out.println("Sent message: " + message.getText());
- }
- </pre>
-
- <li>Consume them</li>
- <pre class="prettyprint">
- for (int i = 0; i < numMessages; i++)
- {
- TextMessage message = (TextMessage)consumer.receive(5000);
- System.out.println("Got message: " + message.getText());
- message.acknowledge();
- }
- </pre>
-
<li>And finally, <strong>always</strong> remember to close your
resources after use, in a <code>finally</code> block. Closing a JMS connection
will automatically close all of its sessions, consumers, producer and browser
objects</li>
<pre class="prettyprint">
Modified:
trunk/examples/jms/non-transaction-failover/src/org/hornetq/jms/example/NonTransactionFailoverExample.java
===================================================================
---
trunk/examples/jms/non-transaction-failover/src/org/hornetq/jms/example/NonTransactionFailoverExample.java 2009-12-04
15:46:18 UTC (rev 8556)
+++
trunk/examples/jms/non-transaction-failover/src/org/hornetq/jms/example/NonTransactionFailoverExample.java 2009-12-04
16:10:51 UTC (rev 8557)
@@ -104,15 +104,10 @@
}
catch (JMSException e)
{
- System.out.println("Got exception while acknowledging message: " +
e.getMessage());
- // Step 12. Close the JMS session and recreate the JMS objects
- session.close();
- session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- producer = session.createProducer(queue);
- consumer = session.createConsumer(queue);
+ System.err.println("Got exception while acknowledging message: " +
e.getMessage());
}
- // Step 13. Consume again the 2nd half of the messages again. Note that they are
not considered as redelivered.
+ // Step 12. Consume again the 2nd half of the messages again. Note that they are
not considered as redelivered.
for (int i = numMessages / 2; i < numMessages; i++)
{
message0 = (TextMessage)consumer.receive(5000);
@@ -120,27 +115,11 @@
}
message0.acknowledge();
- // Step 14. Send some more messages
- for (int i = numMessages; i < numMessages * 2; i++)
- {
- TextMessage message = session.createTextMessage("This is text message
" + i);
- producer.send(message);
- System.out.println("Sent message: " + message.getText());
- }
-
- // Step 15. Consume them
- for (int i = 0; i < numMessages; i++)
- {
- TextMessage message = (TextMessage)consumer.receive(5000);
- System.out.println("Got message: " + message.getText());
- message.acknowledge();
- }
-
return true;
}
finally
{
- // Step 16. Be sure to close our resources!
+ // Step 13. Be sure to close our resources!
if (connection != null)
{
Show replies by date