Continuing work on ARTEMIS-178

This commit is contained in:
jbertram 2015-07-06 14:42:36 -05:00
parent b3af4bb777
commit 54d0d2b4ef
447 changed files with 4592 additions and 8320 deletions

View File

@ -121,6 +121,9 @@ public class Create extends InputAbstract
@Option(name = "--slave", description = "Valid for shared store or replication: this is a slave server?")
boolean slave;
@Option(name = "--failover-on-shutdown", description = "Valid for shared store: will shutdown trigger a failover? (Default: false)")
boolean failoverOnShutodwn;
@Option(name = "--cluster-user", description = "The cluster user to use for clustering. (Default: input)")
String clusterUser = null;
@ -424,6 +427,16 @@ public class Create extends InputAbstract
this.slave = slave;
}
public boolean isFailoverOnShutodwn()
{
return failoverOnShutodwn;
}
public void setFailoverOnShutodwn(boolean failoverOnShutodwn)
{
this.failoverOnShutodwn = failoverOnShutodwn;
}
public Boolean getAllowAnonymous()
{
return allowAnonymous;
@ -494,6 +507,8 @@ public class Create extends InputAbstract
filters.put("${master-slave}", isSlave() ? "slave" : "master");
filters.put("${failover-on-shutdown}", isFailoverOnShutodwn() ? "true" : "false");
if (replicated)
{
clustered = true;

View File

@ -36,7 +36,7 @@ public class ProcessBuilder
{
for (Process p : processes)
{
if (p.isAlive())
// if (p.isAlive())
{
p.destroy();
}
@ -53,7 +53,7 @@ public class ProcessBuilder
{
for (Process p: processes)
{
if (!p.isAlive())
// if (!p.isAlive())
{
processes.remove(p);
}
@ -93,14 +93,14 @@ public class ProcessBuilder
ProcessLogger outputLogger = new ProcessLogger(true,
process.getInputStream(),
logname + "::Out",
logname,
false);
outputLogger.start();
// Adding a reader to System.err, so the VM won't hang on a System.err.println as identified on this forum thread:
ProcessLogger errorLogger = new ProcessLogger(true,
process.getErrorStream(),
logname + "::Err",
logname,
true);
errorLogger.start();
@ -172,11 +172,11 @@ public class ProcessBuilder
{
if (sendToErr)
{
System.err.println(logName + " err:" + line);
System.err.println(logName + "-err:" + line);
}
else
{
System.out.println(logName + " out:" + line);
System.out.println(logName + "-out:" + line);
}
}
}

View File

@ -0,0 +1,207 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.artemis.util;
import org.apache.activemq.artemis.api.core.TransportConfiguration;
import org.apache.activemq.artemis.api.core.client.ClientSession;
import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
import org.apache.activemq.artemis.api.jms.JMSFactoryType;
import org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory;
import org.apache.activemq.artemis.jms.client.ActiveMQConnection;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
import javax.jms.Connection;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
public class ServerUtil
{
public static Process startServer(String artemisInstance, String serverName) throws Exception
{
return startServer(artemisInstance, serverName, 0, 0);
}
public static Process startServer(String artemisInstance, String serverName, int id, int timeout) throws Exception
{
boolean IS_WINDOWS = System.getProperty("os.name").toLowerCase().trim().startsWith("win");
ProcessBuilder builder = null;
if (IS_WINDOWS)
{
builder = new ProcessBuilder("cmd", "/c", "artemis.cmd", "run");
}
else
{
builder = new ProcessBuilder("./artemis", "run");
}
builder.directory(new File(artemisInstance + "/bin"));
final Process process = builder.start();
Runtime.getRuntime().addShutdownHook(new Thread()
{
public void run()
{
process.destroy();
}
});
ProcessLogger outputLogger = new ProcessLogger(true,
process.getInputStream(),
serverName,
false);
outputLogger.start();
// Adding a reader to System.err, so the VM won't hang on a System.err.println as identified on this forum thread:
// http://www.jboss.org/index.html?module=bb&op=viewtopic&t=151815
ProcessLogger errorLogger = new ProcessLogger(true,
process.getErrorStream(),
serverName,
true);
errorLogger.start();
// wait for start
if (timeout != 0)
{
waitForServerToStart(id, timeout);
}
return process;
}
public static void waitForServerToStart(int id, int timeout) throws InterruptedException
{
long realTimeout = System.currentTimeMillis() + timeout;
while (System.currentTimeMillis() < realTimeout)
{
try
{
HashMap<String, Object> params = new HashMap<String, Object>();
params.put("host", "localhost");
params.put("port", 61616 + id);
TransportConfiguration transportConfiguration = new TransportConfiguration(NettyConnectorFactory.class.getName(), params);
ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, transportConfiguration);
cf.createConnection().close();
System.out.println("server " + id + " started");
}
catch (Exception e)
{
System.out.println("awaiting server " + id + " start at " + (61616 + id));
Thread.sleep(500);
continue;
}
break;
}
}
public static void killServer(final Process server) throws Exception
{
if (server != null)
{
System.out.println("**********************************");
System.out.println("Killing server " + server);
System.out.println("**********************************");
server.destroy();
server.waitFor();
Thread.sleep(1000);
}
}
public static int getServer(Connection connection)
{
ClientSession session = ((ActiveMQConnection) connection).getInitialSession();
TransportConfiguration transportConfiguration = session.getSessionFactory().getConnectorConfiguration();
String port = (String) transportConfiguration.getParams().get("port");
return Integer.valueOf(port) - 61616;
}
public static Connection getServerConnection(int server, Connection... connections)
{
for (Connection connection : connections)
{
ClientSession session = ((ActiveMQConnection) connection).getInitialSession();
TransportConfiguration transportConfiguration = session.getSessionFactory().getConnectorConfiguration();
String port = (String) transportConfiguration.getParams().get("port");
if (Integer.valueOf(port) == server + 61616)
{
return connection;
}
}
return null;
}
/**
* Redirect the input stream to a logger (as debug logs)
*/
static class ProcessLogger extends Thread
{
private final InputStream is;
private final String logName;
private final boolean print;
private final boolean sendToErr;
ProcessLogger(final boolean print,
final InputStream is,
final String logName,
final boolean sendToErr) throws ClassNotFoundException
{
this.is = is;
this.print = print;
this.logName = logName;
this.sendToErr = sendToErr;
setDaemon(false);
}
@Override
public void run()
{
try
{
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null)
{
if (print)
{
if (sendToErr)
{
System.err.println(logName + "-err:" + line);
}
else
{
System.out.println(logName + "-out:" + line);
}
}
}
}
catch (IOException e)
{
// ok, stream closed
}
}
}
}

View File

@ -1,6 +1,8 @@
<ha-policy>
<shared-store>
<${master-slave}/>
<${master-slave}>
<failover-on-shutdown>${failover-on-shutdown}</failover-on-shutdown>
</${master-slave}>
</shared-store>
</ha-policy>

View File

@ -1850,7 +1850,8 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback
else
{
ActiveMQJMSServerLogger.LOGGER.serverCachingCommand(runnable);
cachedCommands.add(runnable);
if (!cachedCommands.contains(runnable))
cachedCommands.add(runnable);
return false;
}
}

View File

@ -104,9 +104,15 @@ public class ActiveMQCreatePlugin extends AbstractMojo
@Parameter(defaultValue = "false")
private boolean slave;
@Parameter(defaultValue = "../data")
@Parameter(defaultValue = "./data")
String dataFolder;
@Parameter(defaultValue = "false")
private boolean failoverOnShutdown;
@Parameter(defaultValue = "ON_DEMAND")
private String messageLoadBalancing;
@Component
private RepositorySystem repositorySystem;
@ -162,6 +168,10 @@ public class ActiveMQCreatePlugin extends AbstractMojo
public void execute() throws MojoExecutionException, MojoFailureException
{
if (System.getProperty("bypassAddress") != null)
{
System.out.println("BYPASSADDRESS");
}
getLog().info("Local " + localRepository);
MavenProject project = (MavenProject) getPluginContext().get("project");
@ -224,12 +234,7 @@ public class ActiveMQCreatePlugin extends AbstractMojo
add(listCommands, "--replicated");
}
if (replicated)
{
add(listCommands, "--shared-store");
}
if (replicated)
if (sharedStore)
{
add(listCommands, "--shared-store");
}
@ -237,6 +242,12 @@ public class ActiveMQCreatePlugin extends AbstractMojo
if (clustered)
{
add(listCommands, "--clustered");
add(listCommands, "--message-load-balancing", messageLoadBalancing);
}
if (failoverOnShutdown)
{
add(listCommands, "--failover-on-shutdown");
}
add(listCommands, "--verbose");

View File

@ -16,12 +16,6 @@
*/
package org.apache.activemq.artemis.maven;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.util.Map;
import org.apache.activemq.artemis.cli.Artemis;
import org.apache.activemq.artemis.cli.commands.Run;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
@ -34,19 +28,19 @@ import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
@Mojo(name = "cli", defaultPhase = LifecyclePhase.VERIFY)
public class ArtemisCLIPlugin extends AbstractMojo
{
@Parameter
String name;
/**
* The plugin descriptor
*/
private PluginDescriptor descriptor;
@Parameter(defaultValue = "server")
String name;
@Parameter(defaultValue = "${activemq.basedir}", required = true)
private File home;
@ -62,8 +56,17 @@ public class ArtemisCLIPlugin extends AbstractMojo
@Parameter
private boolean spawn = false;
@Parameter(defaultValue = "10000")
private long spawnTimeout;
@Parameter
private boolean testServer;
private String testURI = null;
@Parameter
private String testUser = null;
@Parameter
private String testPassword = null;
/**
@ -120,13 +123,11 @@ public class ArtemisCLIPlugin extends AbstractMojo
}
}
Map properties = getPluginContext();
try
{
if (spawn)
{
final Process process = org.apache.activemq.artemis.cli.process.ProcessBuilder.build("server", location, true, args);
final Process process = org.apache.activemq.artemis.cli.process.ProcessBuilder.build(name, location, true, args);
Runtime.getRuntime().addShutdownHook(new Thread()
{
public void run()
@ -135,14 +136,21 @@ public class ArtemisCLIPlugin extends AbstractMojo
}
});
if (testServer)
if (testURI != null)
{
for (int tryNr = 0; tryNr < 20; tryNr++)
long timeout = System.currentTimeMillis() + spawnTimeout;
while (System.currentTimeMillis() <= timeout)
{
try
try (ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(testURI))
{
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory();
cf.createConnection().close();
if (testUser != null && testPassword != null)
{
cf.createConnection(testUser, testPassword).close();
}
else
{
cf.createConnection().close();
}
getLog().info("Server started");
}
catch (Exception e)

View File

@ -86,6 +86,4 @@ under the License.
</build>
</profile>
</profiles>
</project>

View File

@ -51,11 +51,6 @@ under the License.
<artifactId>netty-all</artifactId>
<version>${netty.version}</version>
</dependency>
<dependency>
<groupId>org.apache.activemq.examples.jms</groupId>
<artifactId>common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jms_2.0_spec</artifactId>
@ -64,7 +59,7 @@ under the License.
<profiles>
<profile>
<id>default</id>
<id>server</id>
<build>
<plugins>
<plugin>
@ -72,26 +67,16 @@ under the License.
<artifactId>artemis-maven-plugin</artifactId>
<executions>
<execution>
<id>start</id>
<id>create0</id>
<goals>
<goal>start</goal>
<goal>create</goal>
</goals>
<configuration>
<waitOnStart>true</waitOnStart>
<configurationDir>${basedir}/target/classes/server0</configurationDir>
<systemProperties>
<property>
<name>build.directory</name>
<value>${basedir}/target/</value>
</property>
</systemProperties>
<instance>${basedir}/target/server0</instance>
<configuration>${basedir}/target/classes/activemq/server0</configuration>
</configuration>
</execution>
</executions>
<configuration>
<waitOnStart>false</waitOnStart>
<configurationDir>${basedir}/target/classes/server0</configurationDir>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.activemq.examples.core</groupId>
@ -175,6 +160,4 @@ under the License.
</build>
</profile>
</profiles>
</project>

View File

@ -22,13 +22,15 @@ under the License.
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:activemq /schema/artemis-server.xsd">
<core xmlns="urn:activemq:core">
<bindings-directory>target/server0/data/messaging/bindings</bindings-directory>
<journal-directory>target/server0/data/messaging/journal</journal-directory>
<bindings-directory>${data.dir:./data}/bindings</bindings-directory>
<large-messages-directory>target/server0/data/messaging/largemessages</large-messages-directory>
<journal-directory>${data.dir:./data}/journal</journal-directory>
<large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory>
<paging-directory>${data.dir:./data}/paging</paging-directory>
<paging-directory>target/server0/data/messaging/paging</paging-directory>
<!-- Acceptors -->
<acceptors>
<acceptor name="netty-acceptor">tcp://localhost:61616?tcpNoDelay=false;tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576</acceptor>

View File

@ -61,24 +61,29 @@ under the License.
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jms_2.0_spec</artifactId>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>${vertx.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-platform</artifactId>
<version>${vertx.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-hazelcast</artifactId>
<version>${vertx.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>${vertx.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-platform</artifactId>
<version>${vertx.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-hazelcast</artifactId>
<version>${vertx.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-vertx-integration</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<profiles>
@ -89,37 +94,41 @@ under the License.
<plugin>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-maven-plugin</artifactId>
<executions>
<execution>
<id>start</id>
<goals>
<goal>start</goal>
</goals>
<configuration>
<systemProperties>
<property>
<name>build.directory</name>
<value>${basedir}/target/</value>
</property>
</systemProperties>
</configuration>
</execution>
<execution>
<id>runClient</id>
<goals>
<goal>runClient</goal>
</goals>
<configuration>
<clientClass>org.apache.activemq.artemis.core.example.VertxConnectorExample</clientClass>
</configuration>
</execution>
<execution>
<id>stop</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
<executions>
<execution>
<id>create0</id>
<goals>
<goal>create</goal>
</goals>
<configuration>
<instance>${basedir}/target/server0</instance>
<configuration>${basedir}/target/classes/activemq/server0</configuration>
</configuration>
</execution>
<execution>
<id>start0</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<spawn>true</spawn>
<location>${basedir}/target/server0</location>
<testURI>tcp://localhost:61616</testURI>
<args>
<param>run</param>
</args>
</configuration>
</execution>
<execution>
<id>runClient</id>
<goals>
<goal>runClient</goal>
</goals>
<configuration>
<clientClass>org.apache.activemq.artemis.core.example.VertxConnectorExample</clientClass>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.activemq.examples.core</groupId>
@ -157,30 +166,24 @@ under the License.
<version>${netty.version}</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>${vertx.version}</version>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>${vertx.version}</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-platform</artifactId>
<version>${vertx.version}</version>
<groupId>io.vertx</groupId>
<artifactId>vertx-platform</artifactId>
<version>${vertx.version}</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-hazelcast</artifactId>
<version>${vertx.version}</version>
<groupId>io.vertx</groupId>
<artifactId>vertx-hazelcast</artifactId>
<version>${vertx.version}</version>
</dependency>
</dependencies>
<configuration>
<waitOnStart>false</waitOnStart>
<configurationDir>${basedir}/target/classes/server0</configurationDir>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@ -1,17 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
guest=guest

View File

@ -1,17 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
guest=guest

View File

@ -28,10 +28,9 @@ under the License.
</parent>
<properties>
<endpoint />
<applicationid />
<mastersecret />
<mavenVersion>2.2.1</mavenVersion>
<endpoint/>
<applicationid/>
<mastersecret/>
<activemq.basedir>${project.basedir}/../../..</activemq.basedir>
</properties>
@ -45,43 +44,6 @@ under the License.
<artifactId>artemis-cli</artifactId>
<version>${project.version}</version>
</dependency>
<!-- maven -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>${mavenVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>${mavenVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>${mavenVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>${mavenVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${mavenVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact-manager</artifactId>
<version>${mavenVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-repository-metadata</artifactId>
<version>${mavenVersion}</version>
</dependency>
</dependencies>
<profiles>
@ -122,8 +84,7 @@ under the License.
</goals>
<configuration>
<spawn>true</spawn>
<testServer>true</testServer>
<!-- this list was extracted from mvn dependency:tree on integration/aerogear -->
<testURI>tcp://localhost:61616</testURI>
<args>
<param>run</param>
</args>
@ -136,9 +97,6 @@ under the License.
</goals>
<configuration>
<clientClass>org.apache.activemq.artemis.jms.example.AerogearExample</clientClass>
<args>
<param>${basedir}/target/server0</param>
</args>
</configuration>
</execution>
<execution>

View File

@ -29,13 +29,13 @@ under the License.
<core xmlns="urn:activemq:core">
<bindings-directory>${data.dir:../data}/bindings</bindings-directory>
<bindings-directory>${data.dir:./data}/bindings</bindings-directory>
<journal-directory>${data.dir:../data}/journal</journal-directory>
<journal-directory>${data.dir:./data}/journal</journal-directory>
<large-messages-directory>${data.dir:../data}/largemessages</large-messages-directory>
<large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory>
<paging-directory>${data.dir:../data}/paging</paging-directory>
<paging-directory>${data.dir:./data}/paging</paging-directory>
<!-- Acceptors -->
<acceptors>
@ -73,6 +73,5 @@ under the License.
<permission type="send" roles="guest"/>
</security-setting>
</security-settings>
</core>
</configuration>

View File

@ -37,8 +37,8 @@ under the License.
<dependencies>
<dependency>
<groupId>org.apache.activemq.examples.jms</groupId>
<artifactId>common</artifactId>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-cli</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
@ -57,7 +57,7 @@ under the License.
<artifactId>artemis-maven-plugin</artifactId>
<executions>
<execution>
<id>create</id>
<id>create0</id>
<goals>
<goal>create</goal>
</goals>
@ -66,7 +66,7 @@ under the License.
</configuration>
</execution>
<execution>
<id>create2</id>
<id>create1</id>
<goals>
<goal>create</goal>
</goals>

View File

@ -16,6 +16,8 @@
*/
package org.apache.activemq.artemis.jms.example;
import org.apache.activemq.artemis.util.ServerUtil;
import java.lang.Object;
import java.lang.String;
import java.util.Hashtable;
@ -32,37 +34,37 @@ import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.InitialContext;
import org.apache.activemq.artemis.common.example.ActiveMQExample;
import javax.naming.NamingException;
/**
* A simple example that demonstrates application-layer failover of the JMS connection from one node to another
* when the live server crashes
*/
public class ApplicationLayerFailoverExample extends ActiveMQExample
public class ApplicationLayerFailoverExample
{
public static void main(final String[] args)
{
new ApplicationLayerFailoverExample().run(args);
}
private static InitialContext initialContext;
private volatile InitialContext initialContext;
private static Connection connection;
private volatile Connection connection;
private static Session session;
private volatile Session session;
private static MessageConsumer consumer;
private volatile MessageConsumer consumer;
private static MessageProducer producer;
private volatile MessageProducer producer;
private static final CountDownLatch failoverLatch = new CountDownLatch(1);
private final CountDownLatch failoverLatch = new CountDownLatch(1);
private static Process server0;
@Override
public boolean runExample() throws Exception
private static Process server1;
public static void main(final String[] args) throws Exception
{
try
{
server0 = ServerUtil.startServer(args[0], ApplicationLayerFailoverExample.class.getSimpleName() + "0", 0, 5000);
server1 = ServerUtil.startServer(args[1], ApplicationLayerFailoverExample.class.getSimpleName() + "1", 1, 5000);
// Step 1. We create our JMS Connection, Session, MessageProducer and MessageConsumer on server 1.
createJMSObjects(0);
@ -99,21 +101,12 @@ public class ApplicationLayerFailoverExample extends ActiveMQExample
System.out.println("Killing the server");
killServer(0);
// this utility method will wait for the server1 to be activated
waitForServerStart(1, 20000);
ServerUtil.killServer(server0);
// Step 6. Wait for the client side to register the failure and reconnect
boolean ok = failoverLatch.await(5000, TimeUnit.MILLISECONDS);
if (!ok)
{
return false;
}
System.out.println("Reconnection has occurred. Now sending more messages.");
// Step 8. We now send some more messages
@ -135,23 +128,21 @@ public class ApplicationLayerFailoverExample extends ActiveMQExample
System.out.println("Got message: " + message0.getText());
}
return true;
}
catch(Throwable t)
{
t.printStackTrace();
return false;
}
finally
{
// Step 14. Be sure to close our resources!
closeResources();
ServerUtil.killServer(server0);
ServerUtil.killServer(server1);
}
}
private void createJMSObjects(final int server) throws Exception
private static void createJMSObjects(final int server) throws Exception
{
// Step 1. Get an initial context for looking up JNDI from the server
Hashtable<String, Object> properties = new Hashtable<String, Object>();
@ -182,20 +173,34 @@ public class ApplicationLayerFailoverExample extends ActiveMQExample
producer = session.createProducer(queue);
}
private void closeResources() throws Exception
private static void closeResources()
{
if (initialContext != null)
{
initialContext.close();
try
{
initialContext.close();
}
catch (NamingException e)
{
e.printStackTrace();
}
}
if (connection != null)
{
connection.close();
try
{
connection.close();
}
catch (JMSException e)
{
e.printStackTrace();
}
}
}
private class ExampleListener implements ExceptionListener
private static class ExampleListener implements ExceptionListener
{
public void onException(final JMSException exception)
{

View File

@ -27,20 +27,15 @@ under the License.
<version>1.0.1-SNAPSHOT</version>
</parent>
<artifactId>artemis-jms-bridge-example</artifactId>
<artifactId>artemis-jms-core-bridge-example</artifactId>
<packaging>jar</packaging>
<name>ActiveMQ Artemis JMS Bridge Example</name>
<name>ActiveMQ Artemis Core Bridge Example</name>
<properties>
<activemq.basedir>${project.basedir}/../../..</activemq.basedir>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.activemq.examples.jms</groupId>
<artifactId>common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-server</artifactId>
@ -62,7 +57,7 @@ under the License.
<artifactId>artemis-maven-plugin</artifactId>
<executions>
<execution>
<id>create</id>
<id>create0</id>
<goals>
<goal>create</goal>
</goals>
@ -72,7 +67,7 @@ under the License.
</configuration>
</execution>
<execution>
<id>create2</id>
<id>create1</id>
<goals>
<goal>create</goal>
</goals>
@ -82,16 +77,66 @@ under the License.
<portOffset>1</portOffset>
</configuration>
</execution>
<execution>
<id>start0</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<spawn>true</spawn>
<location>${basedir}/target/server0</location>
<testURI>tcp://localhost:61616</testURI>
<args>
<param>run</param>
</args>
<name>server0</name>
</configuration>
</execution>
<execution>
<id>start1</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<spawn>true</spawn>
<location>${basedir}/target/server1</location>
<testURI>tcp://localhost:61617</testURI>
<args>
<param>run</param>
</args>
<name>server1</name>
</configuration>
</execution>
<execution>
<id>runClient</id>
<goals>
<goal>client</goal>
<goal>runClient</goal>
</goals>
<configuration>
<clientClass>org.apache.activemq.artemis.jms.example.BridgeExample</clientClass>
</configuration>
</execution>
<execution>
<id>stop0</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<location>${basedir}/target/server0</location>
<args>
<param>${basedir}/target/server0</param>
<param>${basedir}/target/server1</param>
<param>stop</param>
</args>
</configuration>
</execution>
<execution>
<id>stop1</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<location>${basedir}/target/server1</location>
<args>
<param>stop</param>
</args>
</configuration>
</execution>
@ -99,29 +144,9 @@ under the License.
<dependencies>
<dependency>
<groupId>org.apache.activemq.examples.jms</groupId>
<artifactId>artemis-jms-bridge-example</artifactId>
<artifactId>artemis-jms-core-bridge-example</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-core-client</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-jms-client</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>${netty.version}</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jms_2.0_spec</artifactId>
<version>${geronimo.jms.2.spec.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>

View File

@ -26,21 +26,13 @@ import javax.jms.Session;
import javax.naming.InitialContext;
import java.util.Hashtable;
import org.apache.activemq.artemis.common.example.ActiveMQExample;
/**
* This example demonstrates a core bridge set-up between two nodes, consuming messages from a queue
* on one node and forwarding them to an address on the second node.
*/
public class BridgeExample extends ActiveMQExample
public class BridgeExample
{
public static void main(final String[] args)
{
new BridgeExample().run(args);
}
@Override
public boolean runExample() throws Exception
public static void main(final String[] args) throws Exception
{
Connection connection0 = null;
@ -120,9 +112,9 @@ public class BridgeExample extends ActiveMQExample
producer.send(message);
System.out.println("Sent " + message.getStringProperty("name") +
" message with " +
message.getStringProperty("hat") +
" hat to sausage-factory on node 0");
" message with " +
message.getStringProperty("hat") +
" hat to sausage-factory on node 0");
// Step 14 - we successfully receive the aardvark message from the mincing-machine one node 1. The aardvark's
// hat is now blue since it has been transformed!
@ -130,9 +122,9 @@ public class BridgeExample extends ActiveMQExample
Message receivedMessage = consumer.receive(5000);
System.out.println("Received " + receivedMessage.getStringProperty("name") +
" message with " +
receivedMessage.getStringProperty("hat") +
" hat from mincing-machine on node 1");
" message with " +
receivedMessage.getStringProperty("hat") +
" hat from mincing-machine on node 1");
// Step 13. We create and send another message, this time representing a sasquatch with a mauve hat to the
// sausage-factory on node 0. This won't be bridged to the mincing-machine since we only want aardvarks, not
@ -147,9 +139,9 @@ public class BridgeExample extends ActiveMQExample
producer.send(message);
System.out.println("Sent " + message.getStringProperty("name") +
" message with " +
message.getStringProperty("hat") +
" hat to sausage-factory on node 0");
" message with " +
message.getStringProperty("hat") +
" hat to sausage-factory on node 0");
// Step 14. We don't receive the message since it has not been bridged.
@ -161,10 +153,8 @@ public class BridgeExample extends ActiveMQExample
}
else
{
return false;
throw new IllegalStateException();
}
return true;
}
finally
{
@ -191,5 +181,4 @@ public class BridgeExample extends ActiveMQExample
}
}
}
}

View File

@ -36,11 +36,6 @@ under the License.
</properties>
<dependencies>
<dependency>
<groupId>org.apache.activemq.examples.jms</groupId>
<artifactId>common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jms_2.0_spec</artifactId>
@ -63,6 +58,19 @@ under the License.
<goal>create</goal>
</goals>
</execution>
<execution>
<id>start</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<spawn>true</spawn>
<testURI>tcp://localhost:61616</testURI>
<args>
<param>run</param>
</args>
</configuration>
</execution>
<execution>
<id>runClient</id>
<goals>
@ -70,8 +78,16 @@ under the License.
</goals>
<configuration>
<clientClass>org.apache.activemq.artemis.jms.example.QueueBrowserExample</clientClass>
</configuration>
</execution>
<execution>
<id>stop</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<args>
<param>${basedir}/target/server0</param>
<param>stop</param>
</args>
</configuration>
</execution>

View File

@ -27,20 +27,12 @@ import javax.jms.TextMessage;
import javax.naming.InitialContext;
import java.util.Enumeration;
import org.apache.activemq.artemis.common.example.ActiveMQExample;
/**
* A simple example which shows how to use a QueueBrowser to look at messages of a queue without removing them from the queue
*/
public class QueueBrowserExample extends ActiveMQExample
public class QueueBrowserExample
{
public static void main(final String[] args)
{
new QueueBrowserExample().run(args);
}
@Override
public boolean runExample() throws Exception
public static void main(final String[] args) throws Exception
{
Connection connection = null;
InitialContext initialContext = null;
@ -98,9 +90,6 @@ public class QueueBrowserExample extends ActiveMQExample
System.out.println("Received message: " + messageReceived.getText());
messageReceived = (TextMessage)messageConsumer.receive(5000);
System.out.println("Received message: " + messageReceived.getText());
return true;
}
finally
{

View File

@ -36,11 +36,6 @@ under the License.
</properties>
<dependencies>
<dependency>
<groupId>org.apache.activemq.examples.jms</groupId>
<artifactId>common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-core-client</artifactId>
@ -71,6 +66,19 @@ under the License.
<javaOptions>-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=3000 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false</javaOptions>
</configuration>
</execution>
<execution>
<id>start</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<spawn>true</spawn>
<testURI>tcp://localhost:61616</testURI>
<args>
<param>run</param>
</args>
</configuration>
</execution>
<execution>
<id>runClient</id>
<goals>
@ -78,8 +86,16 @@ under the License.
</goals>
<configuration>
<clientClass>org.apache.activemq.artemis.jms.example.ClientKickoffExample</clientClass>
</configuration>
</execution>
<execution>
<id>stop</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<args>
<param>${basedir}/target/server0</param>
<param>stop</param>
</args>
</configuration>
</execution>

View File

@ -27,27 +27,21 @@ import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import javax.naming.InitialContext;
import java.lang.Exception;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.activemq.artemis.api.core.management.ActiveMQServerControl;
import org.apache.activemq.artemis.api.core.management.ObjectNameBuilder;
import org.apache.activemq.artemis.common.example.ActiveMQExample;
/**
* An example that shows how to kick off a client connected to ActiveMQ Artemis by using JMX.
*/
public class ClientKickoffExample extends ActiveMQExample
public class ClientKickoffExample
{
private static final String JMX_URL = "service:jmx:rmi:///jndi/rmi://localhost:3000/jmxrmi";
public static void main(final String[] args)
{
new ClientKickoffExample().run(args);
}
@Override
public boolean runExample() throws Exception
public static void main(final String[] args) throws Exception
{
QueueConnection connection = null;
InitialContext initialContext = null;
@ -67,7 +61,7 @@ public class ClientKickoffExample extends ActiveMQExample
connection.setExceptionListener(new ExceptionListener()
{
@Override
public void onException(final JMSException e)
public void onException(final JMSException e)
{
exception.set(e);
}
@ -81,9 +75,9 @@ public class ClientKickoffExample extends ActiveMQExample
JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(JMX_URL), new HashMap<String, String>());
MBeanServerConnection mbsc = connector.getMBeanServerConnection();
ActiveMQServerControl serverControl = MBeanServerInvocationHandler.newProxyInstance(mbsc,
on,
ActiveMQServerControl.class,
false);
on,
ActiveMQServerControl.class,
false);
// Step 7. List the remote address connected to the server
System.out.println("List of remote addresses connected to the server:");
@ -107,8 +101,6 @@ public class ClientKickoffExample extends ActiveMQExample
System.err.println("----------------------------------");
exception.get().printStackTrace();
System.err.println("----------------------------------");
return true;
}
finally
{
@ -123,5 +115,4 @@ public class ClientKickoffExample extends ActiveMQExample
}
}
}
}

View File

@ -27,13 +27,13 @@ under the License.
<core xmlns="urn:activemq:core">
<bindings-directory>${data.dir}/server0/data/messaging/bindings</bindings-directory>
<bindings-directory>${data.dir:../data}/bindings</bindings-directory>
<journal-directory>${data.dir}/server0/data/messaging/journal</journal-directory>
<journal-directory>${data.dir:../data}/journal</journal-directory>
<large-messages-directory>${data.dir}/server0/data/messaging/largemessages</large-messages-directory>
<large-messages-directory>${data.dir:../data}/largemessages</large-messages-directory>
<paging-directory>${data.dir}/server0/data/messaging/paging</paging-directory>
<paging-directory>${data.dir:../data}/paging</paging-directory>
<!-- true to expose ActiveMQ Artemis resources through JMX -->
<jmx-management-enabled>true</jmx-management-enabled>

View File

@ -37,8 +37,13 @@ under the License.
<dependencies>
<dependency>
<groupId>org.apache.activemq.examples.jms</groupId>
<artifactId>common</artifactId>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-cli</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-jms-client</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
@ -57,31 +62,31 @@ under the License.
<artifactId>artemis-maven-plugin</artifactId>
<executions>
<execution>
<id>create</id>
<id>create0</id>
<goals>
<goal>create</goal>
</goals>
<configuration>
<instance>${basedir}/target/server0</instance>
<data>../../shared/</data>
<dataFolder>../shared</dataFolder>
<sharedStore>true</sharedStore>
<slave>false</slave>
<failoverOnShutdown>true</failoverOnShutdown>
</configuration>
</execution>
<execution>
<id>create2</id>
<id>create1</id>
<goals>
<goal>create</goal>
</goals>
<configuration>
<instance>${basedir}/target/server1</instance>
<data>../../shared/</data>
<dataFolder>../shared</dataFolder>
<sharedStore>true</sharedStore>
<slave>true</slave>
<portOffset>1</portOffset>
</configuration>
</execution>
<execution>
<id>runClient</id>
<goals>

View File

@ -16,6 +16,11 @@
*/
package org.apache.activemq.artemis.jms.example;
import org.apache.activemq.artemis.api.core.client.FailoverEventListener;
import org.apache.activemq.artemis.api.core.client.FailoverEventType;
import org.apache.activemq.artemis.jms.client.ActiveMQConnection;
import org.apache.activemq.artemis.util.ServerUtil;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.MessageConsumer;
@ -25,38 +30,19 @@ import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.InitialContext;
import org.apache.activemq.artemis.api.core.client.FailoverEventListener;
import org.apache.activemq.artemis.api.core.client.FailoverEventType;
import org.apache.activemq.artemis.common.example.ActiveMQExample;
import org.apache.activemq.artemis.jms.client.ActiveMQConnection;
/**
* This example demonstrates how you can listen on failover event on the client side
*
* <p/>
* In this example there are two nodes running in a cluster, both server will be running for start,
* but after a while the first server will crash. This will trigger a fail-over event
*/
public class ClientSideFailoverListerExample extends ActiveMQExample
public class ClientSideFailoverListerExample
{
private static Process server0;
private static Process server1;
public static void main(final String[] args) throws Exception
{
new ClientSideFailoverListerExample().run(args);
}
@Override
protected void startServers(String[] serversArgs) throws Exception
{
startServer(0, 5000);
// server 1 is a backup, it's not activated
startServer(1, 0);
Thread.sleep(1000);
}
@Override
public boolean runExample() throws Exception
{
InitialContext initialContext = null;
@ -64,20 +50,23 @@ public class ClientSideFailoverListerExample extends ActiveMQExample
try
{
server0 = ServerUtil.startServer(args[0], ClientSideFailoverListerExample.class.getSimpleName() + "0", 0, 5000);
server1 = ServerUtil.startServer(args[1], ClientSideFailoverListerExample.class.getSimpleName() + "1", 1, 0);
// Step 1. Get an initial context for looking up JNDI from server 0
initialContext = new InitialContext();
// Step 2. Look-up the JMS Queue object from JNDI
Queue queue = (Queue)initialContext.lookup("queue/exampleQueue");
Queue queue = (Queue) initialContext.lookup("queue/exampleQueue");
// Step 3. Look-up a JMS Connection Factory object from JNDI on server 0
ConnectionFactory connectionFactory = (ConnectionFactory)initialContext.lookup("ConnectionFactory");
ConnectionFactory connectionFactory = (ConnectionFactory) initialContext.lookup("ConnectionFactory");
// Step 4. We create 1 JMS connections from the same connection factory.
// Wait a little while to make sure broadcasts from all nodes have reached the client
Thread.sleep(5000);
connectionA = connectionFactory.createConnection();
((ActiveMQConnection)connectionA).setFailoverListener(new FailoverListenerImpl());
((ActiveMQConnection) connectionA).setFailoverListener(new FailoverListenerImpl());
// Step 5. We create JMS Sessions
Session sessionA = connectionA.createSession(false, Session.AUTO_ACKNOWLEDGE);
@ -102,8 +91,6 @@ public class ClientSideFailoverListerExample extends ActiveMQExample
// Step 9. We consume messages from the session A, one at a time.
// We reached message no 5 the first server will crash
consume(sessionA, queue, numMessages, "A");
return true;
}
finally
{
@ -118,20 +105,23 @@ public class ClientSideFailoverListerExample extends ActiveMQExample
{
initialContext.close();
}
ServerUtil.killServer(server0);
ServerUtil.killServer(server1);
}
}
private void consume(Session session, Queue queue, int numMessages, String node) throws Exception
private static void consume(Session session, Queue queue, int numMessages, String node) throws Exception
{
MessageConsumer consumer = session.createConsumer(queue);
for (int i = 0; i < numMessages; i++)
{
TextMessage message = (TextMessage)consumer.receive(2000);
TextMessage message = (TextMessage) consumer.receive(2000);
System.out.println("Got message: " + message.getText() + " from node " + node);
if (i == 5)
{
killServer(0);
ServerUtil.killServer(server0);
}
}

View File

@ -37,8 +37,8 @@ under the License.
<dependencies>
<dependency>
<groupId>org.apache.activemq.examples.jms</groupId>
<artifactId>common</artifactId>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-jms-client</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
@ -57,14 +57,24 @@ under the License.
<artifactId>artemis-maven-plugin</artifactId>
<executions>
<execution>
<id>create</id>
<id>create0</id>
<goals>
<goal>create</goal>
</goals>
<configuration>
<instance>${basedir}/target/server0</instance>
<clustered>true</clustered>
<configuration>${basedir}/target/classes/activemq/server0</configuration>
</configuration>
</execution>
<execution>
<id>create1</id>
<goals>
<goal>create</goal>
</goals>
<configuration>
<instance>${basedir}/target/server1</instance>
<clustered>true</clustered>
<portOffset>1</portOffset>
</configuration>
</execution>
<execution>
@ -72,26 +82,57 @@ under the License.
<goals>
<goal>create</goal>
</goals>
<configuration>
<instance>${basedir}/target/server1</instance>
<clustered>true</clustered>
<configuration>${basedir}/target/classes/activemq/server1</configuration>
<portOffset>1</portOffset>
</configuration>
</execution>
<execution>
<id>create3</id>
<goals>
<goal>create</goal>
</goals>
<configuration>
<instance>${basedir}/target/server2</instance>
<clustered>true</clustered>
<configuration>${basedir}/target/classes/activemq/server2</configuration>
<portOffset>2</portOffset>
</configuration>
</execution>
<execution>
<id>start0</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<spawn>true</spawn>
<location>${basedir}/target/server0</location>
<testURI>tcp://localhost:61616</testURI>
<args>
<param>run</param>
</args>
<name>server0</name>
</configuration>
</execution>
<execution>
<id>start1</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<spawn>true</spawn>
<location>${basedir}/target/server1</location>
<testURI>tcp://localhost:61617</testURI>
<args>
<param>run</param>
</args>
<name>server1</name>
</configuration>
</execution>
<execution>
<id>start2</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<spawn>true</spawn>
<location>${basedir}/target/server2</location>
<testURI>tcp://localhost:61618</testURI>
<args>
<param>run</param>
</args>
<name>server2</name>
</configuration>
</execution>
<execution>
<id>runClient</id>
<goals>
@ -99,10 +140,41 @@ under the License.
</goals>
<configuration>
<clientClass>org.apache.activemq.artemis.jms.example.ClientSideLoadBalancingExample</clientClass>
</configuration>
</execution>
<execution>
<id>stop0</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<location>${basedir}/target/server0</location>
<args>
<param>${basedir}/target/server0</param>
<param>${basedir}/target/server1</param>
<param>${basedir}/target/server2</param>
<param>stop</param>
</args>
</configuration>
</execution>
<execution>
<id>stop1</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<location>${basedir}/target/server1</location>
<args>
<param>stop</param>
</args>
</configuration>
</execution>
<execution>
<id>stop2</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<location>${basedir}/target/server2</location>
<args>
<param>stop</param>
</args>
</configuration>
</execution>

View File

@ -26,8 +26,6 @@ import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.InitialContext;
import org.apache.activemq.artemis.common.example.ActiveMQExample;
/**
* This example demonstrates how sessions created from a single connection can be load
* balanced across the different nodes of the cluster.
@ -35,15 +33,9 @@ import org.apache.activemq.artemis.common.example.ActiveMQExample;
* In this example there are three nodes and we use a round-robin client side load-balancing
* policy.
*/
public class ClientSideLoadBalancingExample extends ActiveMQExample
public class ClientSideLoadBalancingExample
{
public static void main(final String[] args)
{
new ClientSideLoadBalancingExample().run(args);
}
@Override
public boolean runExample() throws Exception
public static void main(final String[] args) throws Exception
{
InitialContext initialContext = null;
@ -116,8 +108,6 @@ public class ClientSideLoadBalancingExample extends ActiveMQExample
consume(sessionA, queue, numMessages, "A");
consume(sessionB, queue, numMessages, "B");
consume(sessionC, queue, numMessages, "C");
return true;
}
finally
{
@ -143,7 +133,7 @@ public class ClientSideLoadBalancingExample extends ActiveMQExample
}
}
private void consume(Session session, Queue queue, int numMessages, String node) throws JMSException
private static void consume(Session session, Queue queue, int numMessages, String node) throws JMSException
{
MessageConsumer consumer = session.createConsumer(queue);
@ -154,6 +144,5 @@ public class ClientSideLoadBalancingExample extends ActiveMQExample
}
System.out.println("receive other message from node " + node + ": " + consumer.receive(2000));
}
}

View File

@ -36,11 +36,6 @@ under the License.
</properties>
<dependencies>
<dependency>
<groupId>org.apache.activemq.examples.jms</groupId>
<artifactId>common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jms_2.0_spec</artifactId>
@ -57,7 +52,7 @@ under the License.
<artifactId>artemis-maven-plugin</artifactId>
<executions>
<execution>
<id>create</id>
<id>create0</id>
<goals>
<goal>create</goal>
</goals>
@ -67,7 +62,7 @@ under the License.
</configuration>
</execution>
<execution>
<id>create2</id>
<id>create1</id>
<goals>
<goal>create</goal>
</goals>
@ -77,6 +72,36 @@ under the License.
<portOffset>1</portOffset>
</configuration>
</execution>
<execution>
<id>start0</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<spawn>true</spawn>
<location>${basedir}/target/server0</location>
<testURI>tcp://localhost:61616</testURI>
<args>
<param>run</param>
</args>
<name>server0</name>
</configuration>
</execution>
<execution>
<id>start1</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<spawn>true</spawn>
<location>${basedir}/target/server1</location>
<testURI>tcp://localhost:61617</testURI>
<args>
<param>run</param>
</args>
<name>server1</name>
</configuration>
</execution>
<execution>
<id>runClient</id>
<goals>
@ -84,9 +109,29 @@ under the License.
</goals>
<configuration>
<clientClass>org.apache.activemq.artemis.jms.example.ClusteredDurableSubscriptionExample</clientClass>
</configuration>
</execution>
<execution>
<id>stop0</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<location>${basedir}/target/server0</location>
<args>
<param>${basedir}/target/server0</param>
<param>${basedir}/target/server1</param>
<param>stop</param>
</args>
</configuration>
</execution>
<execution>
<id>stop1</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<location>${basedir}/target/server1</location>
<args>
<param>stop</param>
</args>
</configuration>
</execution>

View File

@ -26,23 +26,15 @@ import javax.jms.Topic;
import javax.naming.InitialContext;
import java.util.Hashtable;
import org.apache.activemq.artemis.common.example.ActiveMQExample;
/**
* A simple example that shows a JMS Durable Subscription across two nodes of a cluster.
*
* The same durable subscription can exist on more than one node of the cluster, and messages
* sent to the topic will be load-balanced in a round-robin fashion between the two nodes
*/
public class ClusteredDurableSubscriptionExample extends ActiveMQExample
public class ClusteredDurableSubscriptionExample
{
public static void main(final String[] args)
{
new ClusteredDurableSubscriptionExample().run(args);
}
@Override
public boolean runExample() throws Exception
public static void main(final String[] args) throws Exception
{
Connection connection0 = null;
@ -145,8 +137,6 @@ public class ClusteredDurableSubscriptionExample extends ActiveMQExample
System.out.println("Got message: " + message1.getText() + " from node 1");
}
return true;
}
finally
{
@ -172,5 +162,4 @@ public class ClusteredDurableSubscriptionExample extends ActiveMQExample
}
}
}
}

View File

@ -29,13 +29,13 @@ under the License.
<core xmlns="urn:activemq:core">
<bindings-directory>${data.dir}/server0/data/messaging/bindings</bindings-directory>
<bindings-directory>${data.dir:./data}/bindings</bindings-directory>
<journal-directory>${data.dir}/server0/data/messaging/journal</journal-directory>
<journal-directory>${data.dir:./data}/journal</journal-directory>
<large-messages-directory>${data.dir}/server0/data/messaging/largemessages</large-messages-directory>
<large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory>
<paging-directory>${data.dir}/server0/data/messaging/paging</paging-directory>
<paging-directory>${data.dir:./data}/paging</paging-directory>
<!-- Connectors -->

View File

@ -29,14 +29,13 @@ under the License.
<core xmlns="urn:activemq:core">
<bindings-directory>${data.dir:./data}/bindings</bindings-directory>
<bindings-directory>${data.dir}/server1/data/messaging/bindings</bindings-directory>
<journal-directory>${data.dir:./data}/journal</journal-directory>
<journal-directory>${data.dir}/server1/data/messaging/journal</journal-directory>
<large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory>
<large-messages-directory>${data.dir}/server1/data/messaging/largemessages</large-messages-directory>
<paging-directory>${data.dir}/server1/data/messaging/paging</paging-directory>
<paging-directory>${data.dir:./data}/paging</paging-directory>
<!-- Connectors -->
<connectors>

View File

@ -36,11 +36,6 @@ under the License.
</properties>
<dependencies>
<dependency>
<groupId>org.apache.activemq.examples.jms</groupId>
<artifactId>common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jms_2.0_spec</artifactId>
@ -57,7 +52,7 @@ under the License.
<artifactId>artemis-maven-plugin</artifactId>
<executions>
<execution>
<id>create</id>
<id>create0</id>
<goals>
<goal>create</goal>
</goals>
@ -67,25 +62,68 @@ under the License.
</configuration>
</execution>
<execution>
<id>create2</id>
<id>create1</id>
<goals>
<goal>create</goal>
</goals>
<configuration>
<instance>${basedir}/target/server1</instance>
<configuration>${basedir}/target/classes/activemq/server1</configuration>
<portOffset>1</portOffset>
</configuration>
</execution>
<execution>
<id>create3</id>
<id>create2</id>
<goals>
<goal>create</goal>
</goals>
<configuration>
<instance>${basedir}/target/server2</instance>
<configuration>${basedir}/target/classes/activemq/server2</configuration>
<portOffset>2</portOffset>
</configuration>
</execution>
<execution>
<id>start0</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<spawn>true</spawn>
<location>${basedir}/target/server0</location>
<testURI>tcp://localhost:61616</testURI>
<args>
<param>run</param>
</args>
<name>server0</name>
</configuration>
</execution>
<execution>
<id>start1</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<spawn>true</spawn>
<location>${basedir}/target/server1</location>
<testURI>tcp://localhost:61617</testURI>
<args>
<param>run</param>
</args>
<name>server1</name>
</configuration>
</execution>
<execution>
<id>start2</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<spawn>true</spawn>
<location>${basedir}/target/server2</location>
<testURI>tcp://localhost:61618</testURI>
<args>
<param>run</param>
</args>
<name>server2</name>
</configuration>
</execution>
<execution>
@ -95,10 +133,41 @@ under the License.
</goals>
<configuration>
<clientClass>org.apache.activemq.artemis.jms.example.ClusteredGroupingExample</clientClass>
</configuration>
</execution>
<execution>
<id>stop0</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<location>${basedir}/target/server0</location>
<args>
<param>${basedir}/target/server0</param>
<param>${basedir}/target/server1</param>
<param>${basedir}/target/server2</param>
<param>stop</param>
</args>
</configuration>
</execution>
<execution>
<id>stop1</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<location>${basedir}/target/server1</location>
<args>
<param>stop</param>
</args>
</configuration>
</execution>
<execution>
<id>stop2</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<location>${basedir}/target/server2</location>
<args>
<param>stop</param>
</args>
</configuration>
</execution>

View File

@ -26,21 +26,13 @@ import javax.jms.TextMessage;
import javax.naming.InitialContext;
import java.util.Hashtable;
import org.apache.activemq.artemis.common.example.ActiveMQExample;
/**
* A simple example that demonstrates server side load-balancing of messages between the queue instances on different
* nodes of the cluster.
*/
public class ClusteredGroupingExample extends ActiveMQExample
public class ClusteredGroupingExample
{
public static void main(String[] args)
{
new ClusteredGroupingExample().run(args);
}
@Override
public boolean runExample() throws Exception
public static void main(String[] args) throws Exception
{
Connection connection0 = null;
@ -171,8 +163,6 @@ public class ClusteredGroupingExample extends ActiveMQExample
System.out.println("Got message: " + message0.getText() + " from node 0");
}
return true;
}
finally
{

View File

@ -29,14 +29,13 @@ under the License.
<core xmlns="urn:activemq:core">
<bindings-directory>${data.dir:./data}/bindings</bindings-directory>
<bindings-directory>${data.dir:../data}/bindings</bindings-directory>
<journal-directory>${data.dir:./data}/journal</journal-directory>
<journal-directory>${data.dir:../data}/journal</journal-directory>
<large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory>
<large-messages-directory>${data.dir:../data}/largemessages</large-messages-directory>
<paging-directory>${data.dir:../data}/paging</paging-directory>
<paging-directory>${data.dir:./data}/paging</paging-directory>
<!-- Connectors -->

View File

@ -29,14 +29,13 @@ under the License.
<core xmlns="urn:activemq:core">
<bindings-directory>${data.dir:./data}/bindings</bindings-directory>
<bindings-directory>${data.dir:../data}/bindings</bindings-directory>
<journal-directory>${data.dir:./data}/journal</journal-directory>
<journal-directory>${data.dir:../data}/journal</journal-directory>
<large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory>
<large-messages-directory>${data.dir:../data}/largemessages</large-messages-directory>
<paging-directory>${data.dir:../data}/paging</paging-directory>
<paging-directory>${data.dir:./data}/paging</paging-directory>
<!-- Connectors -->

View File

@ -29,14 +29,13 @@ under the License.
<core xmlns="urn:activemq:core">
<bindings-directory>${data.dir:./data}/bindings</bindings-directory>
<bindings-directory>${data.dir:../data}/bindings</bindings-directory>
<journal-directory>${data.dir:./data}/journal</journal-directory>
<journal-directory>${data.dir:../data}/journal</journal-directory>
<large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory>
<large-messages-directory>${data.dir:../data}/largemessages</large-messages-directory>
<paging-directory>${data.dir:../data}/paging</paging-directory>
<paging-directory>${data.dir:./data}/paging</paging-directory>
<!-- Connectors -->

View File

@ -36,11 +36,6 @@ under the License.
</properties>
<dependencies>
<dependency>
<groupId>org.apache.activemq.examples.jms</groupId>
<artifactId>common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jms_2.0_spec</artifactId>
@ -71,7 +66,7 @@ under the License.
</configuration>
</execution>
<execution>
<id>create2</id>
<id>create1</id>
<goals>
<goal>create</goal>
</goals>
@ -82,7 +77,36 @@ under the License.
</libList>
<instance>${basedir}/target/server1</instance>
<configuration>${basedir}/target/classes/activemq/server1</configuration>
<portOffset>1</portOffset>
</configuration>
</execution>
<execution>
<id>start0</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<spawn>true</spawn>
<location>${basedir}/target/server0</location>
<testURI>tcp://localhost:61616</testURI>
<args>
<param>run</param>
</args>
<name>server0</name>
</configuration>
</execution>
<execution>
<id>start1</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<spawn>true</spawn>
<location>${basedir}/target/server1</location>
<testURI>tcp://localhost:61617</testURI>
<args>
<param>run</param>
</args>
<name>server1</name>
</configuration>
</execution>
<execution>
@ -92,9 +116,29 @@ under the License.
</goals>
<configuration>
<clientClass>org.apache.activemq.artemis.jms.example.ClusteredJgroupsExample</clientClass>
</configuration>
</execution>
<execution>
<id>stop0</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<location>${basedir}/target/server0</location>
<args>
<param>${basedir}/target/server0</param>
<param>${basedir}/target/server1</param>
<param>stop</param>
</args>
</configuration>
</execution>
<execution>
<id>stop1</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<location>${basedir}/target/server1</location>
<args>
<param>stop</param>
</args>
</configuration>
</execution>

View File

@ -26,20 +26,12 @@ import javax.jms.TextMessage;
import javax.naming.InitialContext;
import java.util.Hashtable;
import org.apache.activemq.artemis.common.example.ActiveMQExample;
/**
* A simple example that demonstrates clustering using jgroups.
*/
public class ClusteredJgroupsExample extends ActiveMQExample
public class ClusteredJgroupsExample
{
public static void main(final String[] args)
{
new ClusteredJgroupsExample().run(args);
}
@Override
public boolean runExample() throws Exception
public static void main(final String[] args) throws Exception
{
Connection connection0 = null;
@ -128,8 +120,6 @@ public class ClusteredJgroupsExample extends ActiveMQExample
System.out.println("Got message: " + message1.getText() + " from node 1");
}
return true;
}
finally
{
@ -156,5 +146,4 @@ public class ClusteredJgroupsExample extends ActiveMQExample
}
}
}
}

View File

@ -29,14 +29,13 @@ under the License.
<core xmlns="urn:activemq:core">
<bindings-directory>${data.dir:./data}/bindings</bindings-directory>
<paging-directory>server0/paging</paging-directory>
<journal-directory>${data.dir:./data}/journal</journal-directory>
<bindings-directory>server0/bindings</bindings-directory>
<large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory>
<journal-directory>server0/journal</journal-directory>
<large-messages-directory>server0/large-messages</large-messages-directory>
<paging-directory>${data.dir:./data}/paging</paging-directory>
<!-- Connectors -->

View File

@ -29,14 +29,13 @@ under the License.
<core xmlns="urn:activemq:core">
<bindings-directory>${data.dir:./data}/bindings</bindings-directory>
<paging-directory>server1/paging</paging-directory>
<journal-directory>${data.dir:./data}/journal</journal-directory>
<bindings-directory>server1/bindings</bindings-directory>
<large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory>
<journal-directory>server1/journal</journal-directory>
<large-messages-directory>server1/large-messages</large-messages-directory>
<paging-directory>${data.dir:./data}/paging</paging-directory>
<!-- Connectors -->
<connectors>

View File

@ -36,11 +36,6 @@ under the License.
</properties>
<dependencies>
<dependency>
<groupId>org.apache.activemq.examples.jms</groupId>
<artifactId>common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jms_2.0_spec</artifactId>
@ -57,7 +52,7 @@ under the License.
<artifactId>artemis-maven-plugin</artifactId>
<executions>
<execution>
<id>create</id>
<id>create0</id>
<goals>
<goal>create</goal>
</goals>
@ -67,14 +62,43 @@ under the License.
</configuration>
</execution>
<execution>
<id>create2</id>
<id>create1</id>
<goals>
<goal>create</goal>
</goals>
<configuration>
<instance>${basedir}/target/server1</instance>
<configuration>${basedir}/target/classes/activemq/server1</configuration>
<portOffset>1</portOffset>
</configuration>
</execution>
<execution>
<id>start0</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<spawn>true</spawn>
<location>${basedir}/target/server0</location>
<testURI>tcp://localhost:61616</testURI>
<args>
<param>run</param>
</args>
<name>server0</name>
</configuration>
</execution>
<execution>
<id>start1</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<spawn>true</spawn>
<location>${basedir}/target/server1</location>
<testURI>tcp://localhost:61617</testURI>
<args>
<param>run</param>
</args>
<name>server1</name>
</configuration>
</execution>
<execution>
@ -84,9 +108,29 @@ under the License.
</goals>
<configuration>
<clientClass>org.apache.activemq.artemis.jms.example.ClusteredQueueExample</clientClass>
</configuration>
</execution>
<execution>
<id>stop0</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<location>${basedir}/target/server0</location>
<args>
<param>${basedir}/target/server0</param>
<param>${basedir}/target/server1</param>
<param>stop</param>
</args>
</configuration>
</execution>
<execution>
<id>stop1</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<location>${basedir}/target/server1</location>
<args>
<param>stop</param>
</args>
</configuration>
</execution>

View File

@ -26,21 +26,13 @@ import javax.jms.TextMessage;
import javax.naming.InitialContext;
import java.util.Hashtable;
import org.apache.activemq.artemis.common.example.ActiveMQExample;
/**
* A simple example that demonstrates server side load-balancing of messages between the queue instances on different
* nodes of the cluster.
*/
public class ClusteredQueueExample extends ActiveMQExample
public class ClusteredQueueExample
{
public static void main(final String[] args)
{
new ClusteredQueueExample().run(args);
}
@Override
public boolean runExample() throws Exception
public static void main(final String[] args) throws Exception
{
Connection connection0 = null;
@ -55,7 +47,7 @@ public class ClusteredQueueExample extends ActiveMQExample
// Step 1. Get an initial context for looking up JNDI from server 0
Hashtable<String, Object> properties = new Hashtable<String, Object>();
properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
properties.put("connectionFactory.ConnectionFactory", DEFAULT_TCP1);
properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61616");
properties.put("queue.queue/exampleQueue", "exampleQueue");
ic0 = new InitialContext(properties);
@ -68,7 +60,7 @@ public class ClusteredQueueExample extends ActiveMQExample
// Step 4. Get an initial context for looking up JNDI from server 1
properties = new Hashtable<String, Object>();
properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
properties.put("connectionFactory.ConnectionFactory", DEFAULT_TCP2);
properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61617");
ic1 = new InitialContext(properties);
// Step 5. Look-up a JMS Connection Factory object from JNDI on server 1
@ -129,8 +121,6 @@ public class ClusteredQueueExample extends ActiveMQExample
System.out.println("Got message: " + message1.getText() + " from node 1");
}
return true;
}
finally
{
@ -157,5 +147,4 @@ public class ClusteredQueueExample extends ActiveMQExample
}
}
}
}

View File

@ -1,17 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
guest=guest

View File

@ -1,17 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
guest=guest

View File

@ -29,14 +29,13 @@ under the License.
<core xmlns="urn:activemq:core">
<bindings-directory>${data.dir:./data}/bindings</bindings-directory>
<bindings-directory>target/server0/data/messaging/bindings</bindings-directory>
<journal-directory>${data.dir:./data}/journal</journal-directory>
<journal-directory>target/server0/data/messaging/journal</journal-directory>
<large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory>
<large-messages-directory>target/server0/data/messaging/largemessages</large-messages-directory>
<paging-directory>target/server0/data/messaging/paging</paging-directory>
<paging-directory>${data.dir:./data}/paging</paging-directory>
<!-- Connectors -->
<connectors>

View File

@ -1,17 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
guest=guest

View File

@ -1,17 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
guest=guest

View File

@ -36,11 +36,6 @@ under the License.
</properties>
<dependencies>
<dependency>
<groupId>org.apache.activemq.examples.jms</groupId>
<artifactId>common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jms_2.0_spec</artifactId>
@ -57,7 +52,7 @@ under the License.
<artifactId>artemis-maven-plugin</artifactId>
<executions>
<execution>
<id>create</id>
<id>create0</id>
<goals>
<goal>create</goal>
</goals>
@ -67,25 +62,68 @@ under the License.
</configuration>
</execution>
<execution>
<id>create2</id>
<id>create1</id>
<goals>
<goal>create</goal>
</goals>
<configuration>
<instance>${basedir}/target/server1</instance>
<configuration>${basedir}/target/classes/activemq/server1</configuration>
<portOffset>1</portOffset>
</configuration>
</execution>
<execution>
<id>create3</id>
<id>create2</id>
<goals>
<goal>create</goal>
</goals>
<configuration>
<instance>${basedir}/target/server2</instance>
<configuration>${basedir}/target/classes/activemq/server2</configuration>
<portOffset>2</portOffset>
</configuration>
</execution>
<execution>
<id>start0</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<spawn>true</spawn>
<location>${basedir}/target/server0</location>
<testURI>tcp://localhost:61616</testURI>
<args>
<param>run</param>
</args>
<name>server0</name>
</configuration>
</execution>
<execution>
<id>start1</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<spawn>true</spawn>
<location>${basedir}/target/server1</location>
<testURI>tcp://localhost:61617</testURI>
<args>
<param>run</param>
</args>
<name>server1</name>
</configuration>
</execution>
<execution>
<id>start2</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<spawn>true</spawn>
<location>${basedir}/target/server2</location>
<testURI>tcp://localhost:61618</testURI>
<args>
<param>run</param>
</args>
<name>server2</name>
</configuration>
</execution>
<execution>
@ -95,10 +133,41 @@ under the License.
</goals>
<configuration>
<clientClass>org.apache.activemq.artemis.jms.example.ClusteredStandaloneExample</clientClass>
</configuration>
</execution>
<execution>
<id>stop0</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<location>${basedir}/target/server0</location>
<args>
<param>${basedir}/target/server0</param>
<param>${basedir}/target/server1</param>
<param>${basedir}/target/server2</param>
<param>stop</param>
</args>
</configuration>
</execution>
<execution>
<id>stop1</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<location>${basedir}/target/server1</location>
<args>
<param>stop</param>
</args>
</configuration>
</execution>
<execution>
<id>stop2</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<location>${basedir}/target/server2</location>
<args>
<param>stop</param>
</args>
</configuration>
</execution>

View File

@ -26,17 +26,9 @@ import javax.jms.Topic;
import javax.naming.InitialContext;
import java.util.Hashtable;
import org.apache.activemq.artemis.common.example.ActiveMQExample;
public class ClusteredStandaloneExample extends ActiveMQExample
public class ClusteredStandaloneExample
{
public static void main(final String[] args)
{
new ClusteredStandaloneExample().run(args);
}
@Override
public boolean runExample() throws Exception
public static void main(final String[] args) throws Exception
{
Connection connection0 = null;
@ -52,18 +44,18 @@ public class ClusteredStandaloneExample extends ActiveMQExample
{
Hashtable<String, Object> properties = new Hashtable<String, Object>();
properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
properties.put("connectionFactory.ConnectionFactory", DEFAULT_TCP1);
properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61616");
properties.put("topic.topic/exampleTopic", "exampleTopic");
initialContext0 = new InitialContext(properties);
properties = new Hashtable<String, Object>();
properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
properties.put("connectionFactory.ConnectionFactory", DEFAULT_TCP2);
properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61617");
initialContext1 = new InitialContext(properties);
properties = new Hashtable<String, Object>();
properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
properties.put("connectionFactory.ConnectionFactory", DEFAULT_TCP3);
properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61618");
initialContext2 = new InitialContext(properties);
// First we demonstrate a distributed topic.
@ -125,7 +117,7 @@ public class ClusteredStandaloneExample extends ActiveMQExample
if (message0 == null)
{
return false;
throw new IllegalStateException();
}
// System.out.println("Received message " + message0.getText());
@ -134,7 +126,7 @@ public class ClusteredStandaloneExample extends ActiveMQExample
if (message1 == null)
{
return false;
throw new IllegalStateException();
}
// System.out.println("Received message " + message1.getText());
@ -143,7 +135,7 @@ public class ClusteredStandaloneExample extends ActiveMQExample
if (message2 == null)
{
return false;
throw new IllegalStateException();
}
System.out.println("Received message " + message2.getText());
@ -156,8 +148,6 @@ public class ClusteredStandaloneExample extends ActiveMQExample
messageConsumer1.close();
messageConsumer2.close();
return true;
}
finally
{
@ -188,5 +178,4 @@ public class ClusteredStandaloneExample extends ActiveMQExample
}
}
}
}

View File

@ -1,17 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
guest=guest

View File

@ -1,17 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
guest=guest

View File

@ -29,14 +29,13 @@ under the License.
<core xmlns="urn:activemq:core">
<bindings-directory>${data.dir:./data}/bindings</bindings-directory>
<bindings-directory>target/server0/data/messaging/bindings</bindings-directory>
<journal-directory>${data.dir:./data}/journal</journal-directory>
<journal-directory>target/server0/data/messaging/journal</journal-directory>
<large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory>
<large-messages-directory>target/server0/data/messaging/largemessages</large-messages-directory>
<paging-directory>target/server0/data/messaging/paging</paging-directory>
<paging-directory>${data.dir:./data}/paging</paging-directory>
<!-- Connectors -->
<connectors>

View File

@ -1,17 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
guest=guest

View File

@ -1,17 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
guest=guest

View File

@ -29,14 +29,13 @@ under the License.
<core xmlns="urn:activemq:core">
<bindings-directory>${data.dir:./data}/bindings</bindings-directory>
<bindings-directory>target/server1/data/messaging/bindings</bindings-directory>
<journal-directory>${data.dir:./data}/journal</journal-directory>
<journal-directory>target/server1/data/messaging/journal</journal-directory>
<large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory>
<large-messages-directory>target/server1/data/messaging/largemessages</large-messages-directory>
<paging-directory>target/server1/data/messaging/paging</paging-directory>
<paging-directory>${data.dir:./data}/paging</paging-directory>
<!-- Connectors -->
<connectors>

View File

@ -1,17 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
guest=guest

View File

@ -1,17 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
guest=guest

View File

@ -29,14 +29,13 @@ under the License.
<core xmlns="urn:activemq:core">
<bindings-directory>${data.dir:./data}/bindings</bindings-directory>
<bindings-directory>target/server2/data/messaging/bindings</bindings-directory>
<journal-directory>${data.dir:./data}/journal</journal-directory>
<journal-directory>target/server2/data/messaging/journal</journal-directory>
<large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory>
<large-messages-directory>target/server2/data/messaging/largemessages</large-messages-directory>
<paging-directory>target/server2/data/messaging/paging</paging-directory>
<paging-directory>${data.dir:./data}/paging</paging-directory>
<!-- Connectors -->
<connectors>

View File

@ -37,8 +37,8 @@ under the License.
<dependencies>
<dependency>
<groupId>org.apache.activemq.examples.jms</groupId>
<artifactId>common</artifactId>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-cli</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
@ -57,7 +57,7 @@ under the License.
<artifactId>artemis-maven-plugin</artifactId>
<executions>
<execution>
<id>create</id>
<id>create0</id>
<goals>
<goal>create</goal>
</goals>
@ -67,14 +67,23 @@ under the License.
</configuration>
</execution>
<execution>
<id>create2</id>
<id>create1</id>
<goals>
<goal>create</goal>
</goals>
<configuration>
<instance>${basedir}/target/server1</instance>
<configuration>${basedir}/target/classes/activemq/server1</configuration>
<portOffset>1</portOffset>
</configuration>
</execution>
<execution>
<id>create2</id>
<goals>
<goal>create</goal>
</goals>
<configuration>
<instance>${basedir}/target/server2</instance>
<configuration>${basedir}/target/classes/activemq/server2</configuration>
</configuration>
</execution>
<execution>
@ -83,20 +92,68 @@ under the License.
<goal>create</goal>
</goals>
<configuration>
<instance>${basedir}/target/server2</instance>
<configuration>${basedir}/target/classes/activemq/server2</configuration>
<portOffset>2</portOffset>
<instance>${basedir}/target/server3</instance>
<configuration>${basedir}/target/classes/activemq/server3</configuration>
</configuration>
</execution>
<execution>
<id>create4</id>
<id>start0</id>
<goals>
<goal>create</goal>
<goal>cli</goal>
</goals>
<configuration>
<instance>${basedir}/target/server3</instance>
<configuration>${basedir}/target/classes/activemq/server3</configuration>
<portOffset>3</portOffset>
<spawn>true</spawn>
<location>${basedir}/target/server0</location>
<testURI>tcp://localhost:61616</testURI>
<args>
<param>run</param>
</args>
<name>server0</name>
</configuration>
</execution>
<execution>
<id>start1</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<spawn>true</spawn>
<location>${basedir}/target/server1</location>
<testURI>tcp://localhost:61617</testURI>
<args>
<param>run</param>
</args>
<name>server1</name>
</configuration>
</execution>
<execution>
<id>start2</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<spawn>true</spawn>
<location>${basedir}/target/server2</location>
<testURI>tcp://localhost:61618</testURI>
<args>
<param>run</param>
</args>
<name>server2</name>
</configuration>
</execution>
<execution>
<id>start3</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<spawn>true</spawn>
<location>${basedir}/target/server3</location>
<testURI>tcp://localhost:61619</testURI>
<args>
<param>run</param>
</args>
<name>server3</name>
</configuration>
</execution>
<execution>
@ -106,11 +163,53 @@ under the License.
</goals>
<configuration>
<clientClass>org.apache.activemq.artemis.jms.example.StaticClusteredQueueExample</clientClass>
</configuration>
</execution>
<execution>
<id>stop0</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<location>${basedir}/target/server0</location>
<args>
<param>${basedir}/target/server0</param>
<param>${basedir}/target/server1</param>
<param>${basedir}/target/server2</param>
<param>${basedir}/target/server3</param>
<param>stop</param>
</args>
</configuration>
</execution>
<execution>
<id>stop1</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<location>${basedir}/target/server1</location>
<args>
<param>stop</param>
</args>
</configuration>
</execution>
<execution>
<id>stop2</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<location>${basedir}/target/server2</location>
<args>
<param>stop</param>
</args>
</configuration>
</execution>
<execution>
<id>stop3</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<location>${basedir}/target/server3</location>
<args>
<param>stop</param>
</args>
</configuration>
</execution>

View File

@ -16,6 +16,8 @@
*/
package org.apache.activemq.artemis.jms.example;
import org.apache.activemq.artemis.util.ServerUtil;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.MessageConsumer;
@ -26,21 +28,13 @@ import javax.jms.TextMessage;
import javax.naming.InitialContext;
import java.util.Hashtable;
import org.apache.activemq.artemis.common.example.ActiveMQExample;
/**
* A simple example that demonstrates server side load-balancing of messages between the queue instances on different
* nodes of the cluster. The cluster is created from a static list of nodes.
*/
public class StaticClusteredQueueExample extends ActiveMQExample
public class StaticClusteredQueueExample
{
public static void main(final String[] args)
{
new StaticClusteredQueueExample().run(args);
}
@Override
public boolean runExample() throws Exception
public static void main(final String[] args) throws Exception
{
Connection initialConnection = null;
@ -59,7 +53,7 @@ public class StaticClusteredQueueExample extends ActiveMQExample
// Step 1. Get an initial context for looking up JNDI from server 3
Hashtable<String, Object> properties = new Hashtable<String, Object>();
properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
properties.put("connectionFactory.ConnectionFactory", DEFAULT_TCP4);
properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61619");
properties.put("queue.queue/exampleQueue", "exampleQueue");
ic0 = new InitialContext(properties);
@ -139,14 +133,14 @@ public class StaticClusteredQueueExample extends ActiveMQExample
// We note the messages have been distributed between servers in a round robin fashion
// JMS Queues implement point-to-point message where each message is only ever consumed by a
// maximum of one consumer
int con0Node = getServer(connection0);
int con1Node = getServer(connection1);
int con2Node = getServer(connection2);
int con3Node = getServer(connection3);
int con0Node = ServerUtil.getServer(connection0);
int con1Node = ServerUtil.getServer(connection1);
int con2Node = ServerUtil.getServer(connection2);
int con3Node = ServerUtil.getServer(connection3);
if(con0Node + con1Node + con2Node + con3Node != 6)
{
return false;
throw new IllegalStateException();
}
for (int i = 0; i < numMessages; i += 4)
{
@ -166,8 +160,6 @@ public class StaticClusteredQueueExample extends ActiveMQExample
System.out.println("Got message: " + message3.getText() + " from node " + con3Node);
}
return true;
}
finally
{
@ -204,5 +196,4 @@ public class StaticClusteredQueueExample extends ActiveMQExample
}
}
}
}

View File

@ -1,17 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
guest=guest

View File

@ -1,17 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
guest=guest

View File

@ -29,14 +29,13 @@ under the License.
<core xmlns="urn:activemq:core">
<bindings-directory>${data.dir:./data}/bindings</bindings-directory>
<bindings-directory>${data.dir}/server0/data/messaging/bindings</bindings-directory>
<journal-directory>${data.dir:./data}/journal</journal-directory>
<journal-directory>${data.dir}/server0/data/messaging/journal</journal-directory>
<large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory>
<large-messages-directory>${data.dir}/server0/data/messaging/largemessages</large-messages-directory>
<paging-directory>${data.dir}/server0/data/messaging/paging</paging-directory>
<paging-directory>${data.dir:./data}/paging</paging-directory>
<!-- Connectors -->

View File

@ -1,17 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
guest=guest

View File

@ -1,17 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
guest=guest

View File

@ -29,14 +29,13 @@ under the License.
<core xmlns="urn:activemq:core">
<bindings-directory>${data.dir:./data}/bindings</bindings-directory>
<bindings-directory>${data.dir}/server1/data/messaging/bindings</bindings-directory>
<journal-directory>${data.dir:./data}/journal</journal-directory>
<journal-directory>${data.dir}/server1/data/messaging/journal</journal-directory>
<large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory>
<large-messages-directory>${data.dir}/server1/data/messaging/largemessages</large-messages-directory>
<paging-directory>${data.dir}/server1/data/messaging/paging</paging-directory>
<paging-directory>${data.dir:./data}/paging</paging-directory>
<!-- Connectors -->
<connectors>

View File

@ -1,17 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
guest=guest

View File

@ -1,17 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
guest=guest

View File

@ -26,14 +26,13 @@
<core xmlns="urn:activemq:core">
<bindings-directory>${data.dir:./data}/bindings</bindings-directory>
<bindings-directory>${data.dir}/server2/data/messaging/bindings</bindings-directory>
<journal-directory>${data.dir:./data}/journal</journal-directory>
<journal-directory>${data.dir}/server2/data/messaging/journal</journal-directory>
<large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory>
<large-messages-directory>${data.dir}/server2/data/messaging/largemessages</large-messages-directory>
<paging-directory>${data.dir}/server2/data/messaging/paging</paging-directory>
<paging-directory>${data.dir:./data}/paging</paging-directory>
<!-- Connectors -->
<connectors>

View File

@ -1,17 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
guest=guest

View File

@ -1,17 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
guest=guest

View File

@ -26,14 +26,13 @@
<core xmlns="urn:activemq:core">
<bindings-directory>${data.dir:./data}/bindings</bindings-directory>
<bindings-directory>${data.dir}/server3/data/messaging/bindings</bindings-directory>
<journal-directory>${data.dir:./data}/journal</journal-directory>
<journal-directory>${data.dir}/server3/data/messaging/journal</journal-directory>
<large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory>
<large-messages-directory>${data.dir}/server3/data/messaging/largemessages</large-messages-directory>
<paging-directory>${data.dir}/server3/data/messaging/paging</paging-directory>
<paging-directory>${data.dir:./data}/paging</paging-directory>
<!-- Connectors -->
<connectors>

View File

@ -37,8 +37,8 @@ under the License.
<dependencies>
<dependency>
<groupId>org.apache.activemq.examples.jms</groupId>
<artifactId>common</artifactId>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-cli</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
@ -57,7 +57,7 @@ under the License.
<artifactId>artemis-maven-plugin</artifactId>
<executions>
<execution>
<id>create</id>
<id>create0</id>
<goals>
<goal>create</goal>
</goals>
@ -67,7 +67,7 @@ under the License.
</configuration>
</execution>
<execution>
<id>create2</id>
<id>create1</id>
<goals>
<goal>create</goal>
</goals>
@ -77,7 +77,7 @@ under the License.
</configuration>
</execution>
<execution>
<id>create3</id>
<id>create2</id>
<goals>
<goal>create</goal>
</goals>
@ -86,6 +86,51 @@ under the License.
<configuration>${basedir}/target/classes/activemq/server2</configuration>
</configuration>
</execution>
<execution>
<id>start0</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<spawn>true</spawn>
<location>${basedir}/target/server0</location>
<testURI>tcp://localhost:61616</testURI>
<args>
<param>run</param>
</args>
<name>server0</name>
</configuration>
</execution>
<execution>
<id>start1</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<spawn>true</spawn>
<location>${basedir}/target/server1</location>
<testURI>tcp://localhost:61617</testURI>
<args>
<param>run</param>
</args>
<name>server1</name>
</configuration>
</execution>
<execution>
<id>start2</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<spawn>true</spawn>
<location>${basedir}/target/server2</location>
<testURI>tcp://localhost:61618</testURI>
<args>
<param>run</param>
</args>
<name>server2</name>
</configuration>
</execution>
<execution>
<id>runClient</id>
<goals>
@ -93,10 +138,41 @@ under the License.
</goals>
<configuration>
<clientClass>org.apache.activemq.artemis.jms.example.ClusterStaticOnewayExample</clientClass>
</configuration>
</execution>
<execution>
<id>stop0</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<location>${basedir}/target/server0</location>
<args>
<param>${basedir}/target/server0</param>
<param>${basedir}/target/server1</param>
<param>${basedir}/target/server2</param>
<param>stop</param>
</args>
</configuration>
</execution>
<execution>
<id>stop1</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<location>${basedir}/target/server1</location>
<args>
<param>stop</param>
</args>
</configuration>
</execution>
<execution>
<id>stop2</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<location>${basedir}/target/server2</location>
<args>
<param>stop</param>
</args>
</configuration>
</execution>
@ -113,5 +189,4 @@ under the License.
</build>
</profile>
</profiles>
</project>

View File

@ -16,6 +16,8 @@
*/
package org.apache.activemq.artemis.jms.example;
import org.apache.activemq.artemis.util.ServerUtil;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.MessageConsumer;
@ -26,21 +28,13 @@ import javax.jms.TextMessage;
import javax.naming.InitialContext;
import java.util.Hashtable;
import org.apache.activemq.artemis.common.example.ActiveMQExample;
/**
* A simple example that demonstrates server side load-balancing of messages between the queue instances on different
* nodes of the cluster. The cluster is created from a static list of nodes.
*/
public class ClusterStaticOnewayExample extends ActiveMQExample
public class ClusterStaticOnewayExample
{
public static void main(final String[] args)
{
new ClusterStaticOnewayExample().run(args);
}
@Override
public boolean runExample() throws Exception
public static void main(final String[] args) throws Exception
{
Connection initialConnection = null;
@ -51,13 +45,13 @@ public class ClusterStaticOnewayExample extends ActiveMQExample
Connection connection2 = null;
InitialContext ic0 = null;
Thread.sleep(5000);
try
{
// Step 1. Get an initial context for looking up JNDI from server 0
Hashtable<String, Object> properties = new Hashtable<String, Object>();
properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
properties.put("connectionFactory.ConnectionFactory", DEFAULT_TCP1);
properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61616");
properties.put("queue.queue/exampleQueue", "exampleQueue");
ic0 = new InitialContext(properties);
@ -106,9 +100,9 @@ public class ClusterStaticOnewayExample extends ActiveMQExample
Thread.sleep(4000);
int con0Node = getServer(connection0);
int con1Node = getServer(connection1);
int con2Node = getServer(connection2);
int con0Node = ServerUtil.getServer(connection0);
int con1Node = ServerUtil.getServer(connection1);
int con2Node = ServerUtil.getServer(connection2);
System.out.println("con0Node = " + con0Node);
System.out.println("con1Node = " + con1Node);
@ -116,11 +110,10 @@ public class ClusterStaticOnewayExample extends ActiveMQExample
if(con0Node + con1Node + con2Node != 3)
{
System.out.println("connections not load balanced");
return false;
throw new IllegalStateException("connections not load balanced");
}
// Step 13. We create a JMS MessageProducer object on server 0
Session sendSession = getServerConnection(0, connection0, connection1, connection2).createSession(false, Session.AUTO_ACKNOWLEDGE);
Session sendSession = ServerUtil.getServerConnection(0, connection0, connection1, connection2).createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = sendSession.createProducer(queue);
@ -156,8 +149,6 @@ public class ClusterStaticOnewayExample extends ActiveMQExample
System.out.println("Got message: " + message2.getText() + " from node " + con2Node);
}
return true;
}
finally
{
@ -189,5 +180,4 @@ public class ClusterStaticOnewayExample extends ActiveMQExample
}
}
}
}

View File

@ -1,17 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
guest=guest

View File

@ -1,17 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
guest=guest

View File

@ -26,14 +26,13 @@
<core xmlns="urn:activemq:core">
<bindings-directory>${data.dir:./data}/bindings</bindings-directory>
<bindings-directory>${data.dir}/server0/data/messaging/bindings</bindings-directory>
<journal-directory>${data.dir:./data}/journal</journal-directory>
<journal-directory>${data.dir}/server0/data/messaging/journal</journal-directory>
<large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory>
<large-messages-directory>${data.dir}/server0/data/messaging/largemessages</large-messages-directory>
<paging-directory>${data.dir}/server0/data/messaging/paging</paging-directory>
<paging-directory>${data.dir:./data}/paging</paging-directory>
<!-- Connectors -->

View File

@ -1,17 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
guest=guest

View File

@ -1,17 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
guest=guest

View File

@ -26,14 +26,13 @@
<core xmlns="urn:activemq:core">
<bindings-directory>${data.dir:./data}/bindings</bindings-directory>
<bindings-directory>${data.dir}/server1/data/messaging/bindings</bindings-directory>
<journal-directory>${data.dir:./data}/journal</journal-directory>
<journal-directory>${data.dir}/server1/data/messaging/journal</journal-directory>
<large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory>
<large-messages-directory>${data.dir}/server1/data/messaging/largemessages</large-messages-directory>
<paging-directory>${data.dir}/server1/data/messaging/paging</paging-directory>
<paging-directory>${data.dir:./data}/paging</paging-directory>
<!-- Connectors -->
<connectors>

View File

@ -1,17 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
guest=guest

View File

@ -1,17 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
guest=guest

View File

@ -26,14 +26,13 @@
<core xmlns="urn:activemq:core">
<bindings-directory>${data.dir:./data}/bindings</bindings-directory>
<bindings-directory>${data.dir}/server2/data/messaging/bindings</bindings-directory>
<journal-directory>${data.dir:./data}/journal</journal-directory>
<journal-directory>${data.dir}/server2/data/messaging/journal</journal-directory>
<large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory>
<large-messages-directory>${data.dir}/server2/data/messaging/largemessages</large-messages-directory>
<paging-directory>${data.dir}/server2/data/messaging/paging</paging-directory>
<paging-directory>${data.dir:./data}/paging</paging-directory>
<!-- Connectors -->
<connectors>

View File

@ -36,11 +36,6 @@ under the License.
</properties>
<dependencies>
<dependency>
<groupId>org.apache.activemq.examples.jms</groupId>
<artifactId>common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jms_2.0_spec</artifactId>
@ -57,7 +52,7 @@ under the License.
<artifactId>artemis-maven-plugin</artifactId>
<executions>
<execution>
<id>create</id>
<id>create0</id>
<goals>
<goal>create</goal>
</goals>
@ -67,7 +62,7 @@ under the License.
</configuration>
</execution>
<execution>
<id>create2</id>
<id>create1</id>
<goals>
<goal>create</goal>
</goals>
@ -76,6 +71,36 @@ under the License.
<configuration>${basedir}/target/classes/activemq/server1</configuration>
</configuration>
</execution>
<execution>
<id>start0</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<spawn>true</spawn>
<location>${basedir}/target/server0</location>
<testURI>tcp://localhost:61616</testURI>
<args>
<param>run</param>
</args>
<name>server0</name>
</configuration>
</execution>
<execution>
<id>start1</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<spawn>true</spawn>
<location>${basedir}/target/server1</location>
<testURI>tcp://localhost:61617</testURI>
<args>
<param>run</param>
</args>
<name>server1</name>
</configuration>
</execution>
<execution>
<id>runClient</id>
<goals>
@ -83,9 +108,29 @@ under the License.
</goals>
<configuration>
<clientClass>org.apache.activemq.artemis.jms.example.ClusteredTopicExample</clientClass>
</configuration>
</execution>
<execution>
<id>stop0</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<location>${basedir}/target/server0</location>
<args>
<param>${basedir}/target/server0</param>
<param>${basedir}/target/server1</param>
<param>stop</param>
</args>
</configuration>
</execution>
<execution>
<id>stop1</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<location>${basedir}/target/server1</location>
<args>
<param>stop</param>
</args>
</configuration>
</execution>

View File

@ -26,21 +26,13 @@ import javax.jms.Topic;
import javax.naming.InitialContext;
import java.util.Hashtable;
import org.apache.activemq.artemis.common.example.ActiveMQExample;
/**
* A simple example that shows a JMS Topic clustered across two nodes of a cluster.
* Messages are sent on one node and received by consumers on both nodes.
*/
public class ClusteredTopicExample extends ActiveMQExample
public class ClusteredTopicExample
{
public static void main(final String[] args)
{
new ClusteredTopicExample().run(args);
}
@Override
public boolean runExample() throws Exception
public static void main(final String[] args) throws Exception
{
Connection connection0 = null;
@ -55,7 +47,7 @@ public class ClusteredTopicExample extends ActiveMQExample
// Step 1. Get an initial context for looking up JNDI from server 0
Hashtable<String, Object> properties = new Hashtable<String, Object>();
properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
properties.put("connectionFactory.ConnectionFactory", DEFAULT_TCP1);
properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61616");
properties.put("topic.topic/exampleTopic", "exampleTopic");
ic0 = new InitialContext(properties);
@ -68,7 +60,7 @@ public class ClusteredTopicExample extends ActiveMQExample
// Step 4. Get an initial context for looking up JNDI from server 1
properties = new Hashtable<String, Object>();
properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
properties.put("connectionFactory.ConnectionFactory", DEFAULT_TCP2);
properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61617");
ic1 = new InitialContext(properties);
// Step 5. Look-up a JMS Connection Factory object from JNDI on server 1
@ -128,8 +120,6 @@ public class ClusteredTopicExample extends ActiveMQExample
System.out.println("Got message: " + message1.getText() + " from node 1");
}
return true;
}
finally
{
@ -155,5 +145,4 @@ public class ClusteredTopicExample extends ActiveMQExample
}
}
}
}

View File

@ -1,17 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
guest=guest

View File

@ -1,17 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
guest=guest

View File

@ -29,14 +29,13 @@ under the License.
<core xmlns="urn:activemq:core">
<bindings-directory>${data.dir:./data}/bindings</bindings-directory>
<bindings-directory>${data.dir}/server0/data/messaging/bindings</bindings-directory>
<journal-directory>${data.dir:./data}/journal</journal-directory>
<journal-directory>${data.dir}/server0/data/messaging/journal</journal-directory>
<large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory>
<large-messages-directory>${data.dir}/server0/data/messaging/largemessages</large-messages-directory>
<paging-directory>${data.dir}/server0/data/messaging/paging</paging-directory>
<paging-directory>${data.dir:./data}/paging</paging-directory>
<!-- Connectors -->

View File

@ -1,17 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
guest=guest

View File

@ -1,17 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
guest=guest

View File

@ -29,14 +29,13 @@ under the License.
<core xmlns="urn:activemq:core">
<bindings-directory>${data.dir:./data}/bindings</bindings-directory>
<bindings-directory>${data.dir}/server1/data/messaging/bindings</bindings-directory>
<journal-directory>${data.dir:./data}/journal</journal-directory>
<journal-directory>${data.dir}/server1/data/messaging/journal</journal-directory>
<large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory>
<large-messages-directory>${data.dir}/server1/data/messaging/largemessages</large-messages-directory>
<paging-directory>${data.dir}/server1/data/messaging/paging</paging-directory>
<paging-directory>${data.dir:./data}/paging</paging-directory>
<!-- Connectors -->
<connectors>

View File

@ -37,8 +37,8 @@ under the License.
<dependencies>
<dependency>
<groupId>org.apache.activemq.examples.jms</groupId>
<artifactId>common</artifactId>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-cli</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
@ -57,7 +57,7 @@ under the License.
<artifactId>artemis-maven-plugin</artifactId>
<executions>
<execution>
<id>create</id>
<id>create0</id>
<goals>
<goal>create</goal>
</goals>
@ -67,7 +67,7 @@ under the License.
</configuration>
</execution>
<execution>
<id>create2</id>
<id>create1</id>
<goals>
<goal>create</goal>
</goals>

View File

@ -16,6 +16,8 @@
*/
package org.apache.activemq.artemis.jms.example;
import org.apache.activemq.artemis.util.ServerUtil;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.MessageConsumer;
@ -24,23 +26,20 @@ import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.InitialContext;
import java.lang.IllegalStateException;
import java.util.Hashtable;
import org.apache.activemq.artemis.common.example.ActiveMQExample;
/**
* A simple example that demonstrates server side load-balancing of messages between the queue instances on different
* nodes of the cluster.
*/
public class ColocatedFailoverScaleDownExample extends ActiveMQExample
public class ColocatedFailoverScaleDownExample
{
public static void main(final String[] args) throws Exception
{
new ColocatedFailoverScaleDownExample().run(args);
}
private static Process server0;
@Override
public boolean runExample() throws Exception
private static Process server1;
public static void main(final String[] args) throws Exception
{
final int numMessages = 30;
@ -52,15 +51,18 @@ public class ColocatedFailoverScaleDownExample extends ActiveMQExample
try
{
server0 = ServerUtil.startServer(args[0], ColocatedFailoverScaleDownExample.class.getSimpleName() + "0", 0, 5000);
server1 = ServerUtil.startServer(args[1], ColocatedFailoverScaleDownExample.class.getSimpleName() + "1", 1, 5000);
// Step 1. Get an initial context for looking up JNDI for both servers
Hashtable<String, Object> properties = new Hashtable<String, Object>();
properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
properties.put("connectionFactory.ConnectionFactory", DEFAULT_TCP2);
properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61617");
initialContext1 = new InitialContext(properties);
properties = new Hashtable<String, Object>();
properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
properties.put("connectionFactory.ConnectionFactory", DEFAULT_TCP1 + "?ha=true&retryInterval=1000&retryIntervalMultiplier=1.0&reconnectAttempts=-1");
properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61616?ha=true&retryInterval=1000&retryIntervalMultiplier=1.0&reconnectAttempts=-1");
properties.put("queue.queue/exampleQueue", "exampleQueue");
initialContext = new InitialContext(properties);
@ -94,10 +96,9 @@ public class ColocatedFailoverScaleDownExample extends ActiveMQExample
// Step 7. Crash server #0, the live server, and wait a little while to make sure
// it has really crashed
killServer(0);
ServerUtil.killServer(server0);
Thread.sleep(5000);
// Step 8. start the connection ready to receive messages
connection1.start();
@ -111,11 +112,13 @@ public class ColocatedFailoverScaleDownExample extends ActiveMQExample
for (int i = 0; i < numMessages * 2; i++)
{
message0 = (TextMessage)consumer.receive(5000);
if (message0 == null)
{
throw new IllegalStateException("Message not received!");
}
System.out.println("Got message: " + message0.getText());
}
message0.acknowledge();
return true;
}
finally
{
@ -139,7 +142,9 @@ public class ColocatedFailoverScaleDownExample extends ActiveMQExample
{
initialContext1.close();
}
ServerUtil.killServer(server0);
ServerUtil.killServer(server1);
}
}
}

View File

@ -1,17 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
guest=guest

View File

@ -1,17 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
guest=guest

View File

@ -29,14 +29,13 @@ under the License.
<core xmlns="urn:activemq:core">
<bindings-directory>${data.dir:../data}/bindings</bindings-directory>
<bindings-directory>../../server0/data/messaging/bindings</bindings-directory>
<journal-directory>${data.dir:../data}/journal</journal-directory>
<journal-directory>../../server0/data/messaging/journal</journal-directory>
<large-messages-directory>${data.dir:../data}/largemessages</large-messages-directory>
<large-messages-directory>../../server0/data/messaging/largemessages</large-messages-directory>
<paging-directory>../../server0/data/messaging/paging</paging-directory>
<paging-directory>${data.dir:../data}/paging</paging-directory>
<!-- Connectors -->
<connectors>
@ -91,7 +90,9 @@ under the License.
<backup-request-retry-interval>2000</backup-request-retry-interval>
<max-backups>1</max-backups>
<request-backup>true</request-backup>
<master/>
<master>
<failover-on-shutdown>true</failover-on-shutdown>
</master>
<slave>
<scale-down/>
</slave>

View File

@ -1,17 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
guest=guest

Some files were not shown because too many files have changed in this diff Show More