Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
499 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE project [ | ||
<!ENTITY libraries SYSTEM "../../../thirdparty/libraries.ent"> | ||
]> | ||
|
||
<!-- =========================================================================================== --> | ||
<!-- --> | ||
<!-- JBoss, Home of Professional Open Source --> | ||
<!-- Copyright 2005, JBoss Inc., and individual contributors as indicated --> | ||
<!-- by the @authors tag. See the copyright.txt in the distribution for a --> | ||
<!-- full listing of individual contributors. --> | ||
<!-- --> | ||
<!-- This is free software; you can redistribute it and/or modify it --> | ||
<!-- under the terms of the GNU Lesser General Public License as --> | ||
<!-- published by the Free Software Foundation; either version 2.1 of --> | ||
<!-- the License, or (at your option) any later version. --> | ||
<!-- --> | ||
<!-- This software is distributed in the hope that it will be useful, --> | ||
<!-- but WITHOUT ANY WARRANTY; without even the implied warranty of --> | ||
<!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --> | ||
<!-- Lesser General Public License for more details. --> | ||
<!-- --> | ||
<!-- You should have received a copy of the GNU Lesser General Public --> | ||
<!-- License along with this software; if not, write to the Free --> | ||
<!-- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA --> | ||
<!-- 02110-1301 USA, or see the FSF site: http://www.fsf.org. --> | ||
<!-- --> | ||
<!-- =========================================================================================== --> | ||
|
||
|
||
<project default="run" name="JBoss Messaging Delayed Redelivery Example"> | ||
|
||
<import file="../common/build.xml"/> | ||
|
||
<target name="run"> | ||
<antcall target="runExample"> | ||
<param name="example.classname" value="org.jboss.jms.example.DelayedRedeliveryExample"/> | ||
</antcall> | ||
</target> | ||
|
||
<target name="runRemote"> | ||
<antcall target="runExample"> | ||
<param name="example.classname" value="org.jboss.jms.example.DelayedRedeliveryExample"/> | ||
<param name="jbm.example.runServer" value="false"/> | ||
</antcall> | ||
</target> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
<html> | ||
<head> | ||
<title>JBoss Messaging Delayed Redelivery Example</title> | ||
<link rel="stylesheet" type="text/css" href="../common/common.css"> | ||
</head> | ||
<body> | ||
<h1>JBoss Messaging Delayed Redelivery Example</h1> | ||
|
||
<p>This example demonstrates how JBoss Messaging can be configured to provide a delayed redelivery in the case | ||
a message needs to be redelivered.</p> | ||
<p>Delaying redelivery can often be useful in the case that clients regularly fail or roll-back. Without a delayed | ||
redelivery, the system can get into a "thrashing" state, with delivery being attempted, the client rolling back, and | ||
delivery being re-attempted ad infinitum in quick succession, using up valuable CPU and network resources.</p> | ||
<p>Re-delivery occurs when the session is closed with unacknowledged messages. The unacknowledged messages will | ||
be redelivered.</p> | ||
<p>By providing a redelivery delay, it can be specified that a delay of, say, 10 seconds is implemented between rollback | ||
and redelivery. The specific delay is configurable on both a global and per destination level, by using wild-card | ||
matching on the address settings.</p> | ||
|
||
<h2>Example setup</h2> | ||
<p>Redelivery delay is specified in the queue settings configuration file <a href="server0/jbm-queues.xml">jbm-queues.xml</a>:</p> | ||
<p>In this example we set the redelivery delay to 5 seconds for the specific example queue. We could set redelivery delay on | ||
on multiple queues by specifying a wild-card in the match, e.g. <code>match="jms.#"</code> would apply the settings | ||
to all JMS queues and topics.</p> | ||
<p>We then consume a message in a transacted session, and rollback, and note that the message is not redelivered until | ||
after 5 seconds.</p> | ||
<pre> | ||
<code><address-settings match="jms.queue.exampleQueue"> | ||
<redelivey-delay>5000</redelivey-delay> | ||
</address-settings> | ||
</code> | ||
</pre> | ||
<p><i>To run the example, simply type <code>ant</code> from this directory</i></p> | ||
<ol> | ||
<li>Create an initial context to perform the JNDI lookup.</li> | ||
<pre> | ||
<code>initialContext = getContext(0);</code> | ||
</pre> | ||
|
||
<li>Perform a lookup on the queue</li> | ||
<pre> | ||
<code>Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue");</code> | ||
</pre> | ||
|
||
<li>Perform a lookup on the Connection Factory</li> | ||
<pre> | ||
<code>ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");</code> | ||
</pre> | ||
|
||
<li>Create a JMS Connection</li> | ||
<pre> | ||
<code>connection = cf.createConnection();</code> | ||
</pre> | ||
|
||
<li>Create a transacted JMS Session | ||
<pre> | ||
<code>Session session = connection.createSession(true, 0);</code> | ||
</pre> | ||
|
||
<li>Create a JMS Message Producer</li> | ||
<pre> | ||
<code>MessageProducer producer = session.createProducer(queue);</code> | ||
</pre> | ||
|
||
<li>Create a Text Message</li> | ||
<pre> | ||
<code>TextMessage message = session.createTextMessage("this is a text message");</code> | ||
</pre> | ||
|
||
<li>Send the Message</li> | ||
<pre> | ||
<code>producer.send(message);</code> | ||
</pre> | ||
|
||
<li>We commit the session to effectively send the message to the queue</li> | ||
<pre> | ||
<code>session.commit();</code> | ||
</pre> | ||
|
||
<li>We create a JMS message consumer on the queue</li> | ||
<pre> | ||
<code>MessageConsumer messageConsumer = session.createConsumer(queue);</code> | ||
</pre> | ||
|
||
<li>We start the connection. In order for delivery to occur on any consumers or subscribers on a connection, the connection must be started</li> | ||
<pre> | ||
<code>connection.start();</code> | ||
</pre> | ||
|
||
<li>We receive the message...</li> | ||
<pre> | ||
<code>TextMessage messageReceived = (TextMessage)messageConsumer.receive(5000); | ||
System.out.println("1st delivery from " + queue.getQueueName() + ": " + messageReceived.getText());</code> | ||
</pre> | ||
|
||
<li>...but we roll back the session. the message returns to the queue, but only after a | ||
5 second delay</li> | ||
<pre> | ||
<code>session.rollback();</code> | ||
</pre> | ||
|
||
<li>We try to receive the message but it's being delayed</li> | ||
<pre> | ||
<code> | ||
messageReceived = (TextMessage)messageConsumer.receive(3000); | ||
|
||
if (messageReceived != null) | ||
{ | ||
return false; | ||
} | ||
|
||
System.out.println("Redelivery has been delayed so received message is " + messageReceived); | ||
|
||
</code> | ||
</pre> | ||
|
||
<li>We try and receive the message again, this time we should get it</li> | ||
<pre> | ||
<code> | ||
messageReceived = (TextMessage)messageConsumer.receive(3000); | ||
|
||
System.out.println("2nd delivery from " + queue.getQueueName() + ": " + messageReceived.getText()); | ||
</code> | ||
</pre> | ||
|
||
<li>We rollback the session again to cause another redelivery, and we time how long this one takes</code> | ||
<pre> | ||
<code> | ||
long start = System.currentTimeMillis(); | ||
|
||
session.rollback(); | ||
|
||
messageReceived = (TextMessage)messageConsumer.receive(8000); | ||
|
||
long end = System.currentTimeMillis(); | ||
|
||
System.out.println("3nd delivery from " + queue.getQueueName() + ": " + messageReceived.getText() + | ||
" after " + (end - start) + " milliseconds."); | ||
</code> | ||
</pre> | ||
|
||
<li>And finally, <b>always</b> remember to close your JMS connections and 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> | ||
<code>finally | ||
{ | ||
if (initialContext != null) | ||
{ | ||
initialContext.close(); | ||
} | ||
if (connection != null) | ||
{ | ||
connection.close(); | ||
} | ||
}</code> | ||
</pre> | ||
</ol> | ||
|
||
</body> | ||
</html> |
3 changes: 3 additions & 0 deletions
3
examples/jms/delayed-redelivery/server0/client-jndi.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory | ||
java.naming.provider.url=jnp://localhost:1099 | ||
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces |
29 changes: 29 additions & 0 deletions
29
examples/jms/delayed-redelivery/server0/jbm-configuration.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<deployment xmlns="urn:jboss:messaging" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-configuration.xsd"> | ||
<configuration> | ||
|
||
<!-- Connectors --> | ||
|
||
<connectors> | ||
<connector name="netty-connector"> | ||
<factory-class>org.jboss.messaging.integration.transports.netty.NettyConnectorFactory</factory-class> | ||
<param key="jbm.remoting.netty.port" value="5445" type="Integer"/> | ||
</connector> | ||
</connectors> | ||
|
||
<!-- Acceptors --> | ||
<acceptors> | ||
<acceptor name="netty-acceptor"> | ||
<factory-class>org.jboss.messaging.integration.transports.netty.NettyAcceptorFactory</factory-class> | ||
<param key="jbm.remoting.netty.port" value="5445" type="Integer"/> | ||
</acceptor> | ||
</acceptors> | ||
|
||
<!-- Other config --> | ||
|
||
<journal-min-files>2</journal-min-files> | ||
|
||
</configuration> | ||
|
||
</deployment> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<deployment xmlns="urn:jboss:messaging" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-jms.xsd "> | ||
<!--the connection factory used by the example--> | ||
<connection-factory name="ConnectionFactory"> | ||
<connector-ref connector-name="netty-connector"/> | ||
<entries> | ||
<entry name="ConnectionFactory"/> | ||
<entry name="XAConnectionFactory"/> | ||
<entry name="java:/ConnectionFactory"/> | ||
<entry name="java:/XAConnectionFactory"/> | ||
</entries> | ||
</connection-factory> | ||
|
||
<!--the queue used by the example--> | ||
<queue name="exampleQueue"> | ||
<entry name="/queue/exampleQueue"/> | ||
</queue> | ||
|
||
<!-- the dead letter queue where dead messages will be sent--> | ||
<queue name="deadLetterQueue"> | ||
<entry name="/queue/deadLetterQueue"/> | ||
</queue> | ||
|
||
</deployment> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<settings xmlns="urn:jboss:messaging" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-queues.xsd "> | ||
|
||
<!--security for example queue--> | ||
<security match="jms.#"> | ||
<permission type="createDurableQueue" roles="guest"/> | ||
<permission type="deleteDurableQueue" roles="guest"/> | ||
<permission type="createTempQueue" roles="guest"/> | ||
<permission type="deleteTempQueue" roles="guest"/> | ||
<permission type="consume" roles="guest"/> | ||
<permission type="send" roles="guest"/> | ||
</security> | ||
|
||
<!--override the redelivery-delay for the example queue--> | ||
<address-settings match="jms.queue.exampleQueue"> | ||
|
||
<redelivery-delay>5000</redelivery-delay> | ||
|
||
</address-settings> | ||
|
||
</settings> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<deployment xmlns="urn:jboss:messaging" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-security.xsd "> | ||
<!-- the default user. this is used where username is null--> | ||
<defaultuser name="guest" password="guest"> | ||
<role name="guest"/> | ||
</defaultuser> | ||
</deployment> |
58 changes: 58 additions & 0 deletions
58
examples/jms/delayed-redelivery/server0/jbm-standalone-beans.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<deployment xmlns="urn:jboss:bean-deployer:2.0"> | ||
|
||
<bean name="Naming" class="org.jnp.server.NamingBeanImpl"/> | ||
|
||
<!-- JNDI server. Disable this if you don't want JNDI --> | ||
<bean name="JNDIServer" class="org.jnp.server.Main"> | ||
<property name="namingInfo"> | ||
<inject bean="Naming"/> | ||
</property> | ||
<property name="port">1099</property> | ||
<property name="bindAddress">localhost</property> | ||
<property name="rmiPort">1098</property> | ||
<property name="rmiBindAddress">localhost</property> | ||
</bean> | ||
|
||
<!-- MBean server --> | ||
<bean name="MBeanServer" class="javax.management.MBeanServer"> | ||
<constructor factoryClass="java.lang.management.ManagementFactory" | ||
factoryMethod="getPlatformMBeanServer"/> | ||
</bean> | ||
|
||
<!-- The core configuration --> | ||
<bean name="Configuration" class="org.jboss.messaging.core.config.impl.FileConfiguration"/> | ||
|
||
<!-- The security manager --> | ||
<bean name="JBMSecurityManager" class="org.jboss.messaging.core.security.impl.JBMSecurityManagerImpl"> | ||
<start ignored="true"/> | ||
<stop ignored="true"/> | ||
</bean> | ||
|
||
<!-- The core server --> | ||
<bean name="MessagingServer" class="org.jboss.messaging.core.server.impl.MessagingServerImpl"> | ||
<constructor> | ||
<parameter> | ||
<inject bean="Configuration"/> | ||
</parameter> | ||
<parameter> | ||
<inject bean="MBeanServer"/> | ||
</parameter> | ||
<parameter> | ||
<inject bean="JBMSecurityManager"/> | ||
</parameter> | ||
</constructor> | ||
</bean> | ||
|
||
<!-- The JMS server --> | ||
<bean name="JMSServerManager" class="org.jboss.messaging.jms.server.impl.JMSServerManagerImpl"> | ||
<constructor> | ||
<parameter> | ||
<inject bean="MessagingServer"/> | ||
</parameter> | ||
</constructor> | ||
</bean> | ||
|
||
|
||
</deployment> |
Oops, something went wrong.