Skip to content

Commit

Permalink
fixed configs and added a standalone config
Browse files Browse the repository at this point in the history
  • Loading branch information
purplefox committed Jun 12, 2009
1 parent cc172a4 commit 42ec994
Show file tree
Hide file tree
Showing 16 changed files with 339 additions and 139 deletions.
1 change: 1 addition & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<classpathentry kind="src" path="examples/jms/client-side-load-balancing/src"/>
<classpathentry kind="src" path="examples/jms/clustered-durable-subscription/src"/>
<classpathentry kind="src" path="examples/jms/clustered-queue/src"/>
<classpathentry kind="src" path="examples/jms/clustered-standalone/src"/>
<classpathentry kind="src" path="examples/jms/clustered-topic/src"/>
<classpathentry kind="src" path="examples/common/src"/>
<classpathentry kind="src" path="examples/jms/consumer-rate-limit/src"/>
Expand Down
1 change: 1 addition & 0 deletions examples/common/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
<jvmarg value="-Djbm.example.server.classpath=${serverclasspath}"/>
<jvmarg value="-Djbm.example.server.args=${server.args}"/>
<jvmarg value="-Djbm.example.logserveroutput=${jbm.example.logserveroutput}"/>
<jvmarg value="-Djbm.example.runServer=${jbm.example.runServer}"/>
<arg line="${jbm.example.beans.file}"/>
<sysproperty key="java.library.path" value="${java.library.path}${path.separator}${aio.library.path}"/>
<classpath refid="client.classpath"/>
Expand Down
42 changes: 42 additions & 0 deletions examples/jms/clustered-standalone/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?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="runRemote" name="JBoss Messaging Clustered Standalone Example">

<import file="../../common/build.xml"/>

<target name="runRemote">
<antcall target="runExample">
<param name="example.classname" value="org.jboss.jms.example.ClusteredStandaloneExample"/>
<param name="jbm.example.runServer" value="false"/>
</antcall>
</target>

</project>
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
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:2099
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
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:3099
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
* 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.
*/
package org.jboss.jms.example;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Topic;
import javax.naming.InitialContext;

import org.jboss.common.example.JBMExample;

/**
*
* This example demonstrates a distributed topic, and needs three servers to be started before the example is run.
*
* The example will not spawn the servers itself.
*
* The servers should be started using ./run.sh ../config/stand-alone/clustered
*
* If running on the same physical box, make sure that each server:
*
* a) uses a different data directory
* b) uses different ports for the netty acceptor
* c) uses different ports for JNDI
*
* Update server[0|1|2]/client-jndi.properties to the correct ports and hosts for the 3 servers
*
* @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
*
*
*/
public class ClusteredStandaloneExample extends JBMExample
{
public static void main(String[] args)
{
new ClusteredStandaloneExample().run(args);
}

public boolean runExample() throws Exception
{
Connection connection0 = null;

Connection connection1 = null;

Connection connection2 = null;

InitialContext initialContext0 = null;
InitialContext initialContext1 = null;
InitialContext initialContext2 = null;

try
{
initialContext0 = getContext(0);

initialContext1 = getContext(1);

initialContext2 = getContext(2);

// First we demonstrate a distributed topic.
// We create a connection on each node, create a consumer on each connection and send some
// messages at a node and verify they are all received by all consumers

ConnectionFactory cf0 = (ConnectionFactory)initialContext0.lookup("/ConnectionFactory");

System.out.println("Got cf " + cf0);

ConnectionFactory cf1 = (ConnectionFactory)initialContext1.lookup("/ConnectionFactory");

System.out.println("Got cf " + cf1);

ConnectionFactory cf2 = (ConnectionFactory)initialContext2.lookup("/ConnectionFactory");

System.out.println("Got cf " + cf2);

Topic topic = (Topic)initialContext0.lookup("/topic/ExampleTopic");


connection0 = cf0.createConnection();

connection1 = cf1.createConnection();

connection2 = cf2.createConnection();

connection0.start();

connection1.start();

connection2.start();

Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE);

Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);

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

MessageConsumer messageConsumer0 = session0.createConsumer(topic);

MessageConsumer messageConsumer1 = session1.createConsumer(topic);

MessageConsumer messageConsumer2 = session2.createConsumer(topic);

MessageProducer producer = session0.createProducer(topic);

final int numMessages = 10;

for (int i = 0; i < numMessages; i++)
{
TextMessage message = session0.createTextMessage("Message " + i);

producer.send(message);
}

for (int i = 0; i < numMessages; i++)
{
TextMessage message0 = (TextMessage)messageConsumer0.receive(2000);

if (message0 == null)
{
return false;
}

System.out.println("Received message " + message0.getText());

TextMessage message1 = (TextMessage)messageConsumer1.receive(2000);

if (message1 == null)
{
return false;
}

System.out.println("Received message " + message1.getText());

TextMessage message2 = (TextMessage)messageConsumer2.receive(2000);

if (message2 == null)
{
return false;
}

System.out.println("Received message " + message2.getText());
}

producer.close();

messageConsumer0.close();

messageConsumer1.close();

messageConsumer2.close();

return true;
}
finally
{
// Step 12. Be sure to close our JMS resources!
if (initialContext0 != null)
{
initialContext0.close();
}
if (initialContext1 != null)
{
initialContext1.close();
}
if (initialContext2 != null)
{
initialContext2.close();
}
if (connection0 != null)
{
connection0.close();
}
if (connection1 != null)
{
connection1.close();
}
if (connection2 != null)
{
connection2.close();
}
}
}

}
40 changes: 9 additions & 31 deletions src/config/jboss-as/clustered/jbm-configuration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,68 +4,46 @@

<clustered>true</clustered>

<!-- Connectors -->
<connectors>
<connector name="netty-backup">
<factory-class>org.jboss.messaging.integration.transports.netty.NettyConnectorFactory</factory-class>
<param key="jbm.remoting.netty.host" value="localhost" type="String"/>
<param key="jbm.remoting.netty.port" value="6400" type="Integer"/>
</connector>
<connectors>
<connector name="netty">
<factory-class>org.jboss.messaging.integration.transports.netty.NettyConnectorFactory</factory-class>
<param key="jbm.remoting.netty.host" value="${jbm.remoting.netty.host:localhost}" type="String"/>
<param key="jbm.remoting.netty.port" value="${jbm.remoting.netty.port:5445}" type="Integer"/>
</connector>
<connector name="in-vm">
<factory-class>org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory</factory-class>
</connector>
</connectors>

<!-- Acceptors -->
<acceptors>
<!-- In VM acceptor -->
<acceptor name="in-vm-acceptor">
<factory-class>org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory</factory-class>
<param key="jbm.remoting.invm.serverid" value="0" type="Integer"/>
</acceptor>

<!-- Netty TCP Acceptor -->
<acceptor name="netty-acceptor">
<acceptor name="netty">
<factory-class>org.jboss.messaging.integration.transports.netty.NettyAcceptorFactory</factory-class>
<param key="jbm.remoting.netty.host" value="${jbm.remoting.netty.host:localhost}" type="String"/>
<param key="jbm.remoting.netty.port" value="${jbm.remoting.netty.port:5445}" type="Integer"/>
</acceptor>
</acceptors>

<!-- Clustering configuration -->
<broadcast-groups>
<broadcast-group name="my-broadcast-group">
<broadcast-group name="bg-group1">
<group-address>231.7.7.7</group-address>
<group-port>9876</group-port>
<broadcast-period>100</broadcast-period>
<broadcast-period>5000</broadcast-period>
<connector-ref connector-name="netty"/>
</broadcast-group>
</broadcast-groups>

<discovery-groups>
<discovery-group name="my-discovery-group">
<discovery-group name="dg-group1">
<group-address>231.7.7.7</group-address>
<group-port>9876</group-port>
<refresh-timeout>10000</refresh-timeout>
</discovery-group>
</discovery-groups>

<cluster-connections>
<cluster-connection name="my-cluster">
<address>jms</address>
<retry-interval>500</retry-interval>
<use-duplicate-detection>true</use-duplicate-detection>
<forward-when-no-consumers>true</forward-when-no-consumers>
<max-hops>1</max-hops>
<discovery-group-ref discovery-group-name="my-discovery-group"/>
<address>jms</address>
<discovery-group-ref discovery-group-name="dg-group1"/>
</cluster-connection>
</cluster-connections>

<security-settings>
<security-setting match="#">
<permission type="createTempQueue" roles="guest"/>
Expand Down
17 changes: 1 addition & 16 deletions src/config/jboss-as/non-clustered/jbm-configuration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,20 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:jboss:messaging /schema/jbm-configuration.xsd">

<!-- Connectors -->
<connectors>
<connector name="netty">
<factory-class>org.jboss.messaging.integration.transports.netty.NettyConnectorFactory</factory-class>
<param key="jbm.remoting.netty.host" value="${jbm.remoting.netty.host:localhost}" type="String"/>
<param key="jbm.remoting.netty.port" value="${jbm.remoting.netty.port:5445}" type="Integer"/>
</connector>

<connector name="in-vm">
<factory-class>org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory</factory-class>
</connector>

</connectors>

<!-- Acceptors -->
<acceptors>
<!-- In VM acceptor -->
<acceptor name="in-vm-acceptor">
<factory-class>org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory</factory-class>
<param key="jbm.remoting.invm.serverid" value="0" type="Integer"/>
</acceptor>

<!-- Netty TCP Acceptor -->
<acceptors>
<acceptor name="netty-acceptor">
<factory-class>org.jboss.messaging.integration.transports.netty.NettyAcceptorFactory</factory-class>
<param key="jbm.remoting.netty.host" value="${jbm.remoting.netty.host:localhost}" type="String"/>
<param key="jbm.remoting.netty.port" value="${jbm.remoting.netty.port:5445}" type="Integer"/>
</acceptor>

</acceptors>

<security-settings>
Expand Down
Loading

0 comments on commit 42ec994

Please sign in to comment.