From 138bfe968259eca3f8be0e98076195a2b4bf2946 Mon Sep 17 00:00:00 2001 From: Clebert Suconic Date: Thu, 6 Aug 2015 10:24:00 -0400 Subject: [PATCH 1/2] Removing 'created by' comments --- .../artemis/core/server/impl/SharedStoreLiveActivation.java | 3 --- .../activemq/artemis/core/transaction/TransactionFactory.java | 3 --- .../activemq/network/MQTTNetworkOfBrokersFailoverTest.java | 4 ---- 3 files changed, 10 deletions(-) diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedStoreLiveActivation.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedStoreLiveActivation.java index 0e41b7aae5..e9b67b8c81 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedStoreLiveActivation.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedStoreLiveActivation.java @@ -20,9 +20,6 @@ import org.apache.activemq.artemis.core.server.ActiveMQServerLogger; import org.apache.activemq.artemis.core.server.NodeManager; import org.apache.activemq.artemis.core.server.cluster.ha.SharedStoreMasterPolicy; -/** -* Created by andy on 04/09/14. -*/ public final class SharedStoreLiveActivation extends LiveActivation { //this is how we act when we initially start as live diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/transaction/TransactionFactory.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/transaction/TransactionFactory.java index 5252f665c7..976543947e 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/transaction/TransactionFactory.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/transaction/TransactionFactory.java @@ -20,9 +20,6 @@ import org.apache.activemq.artemis.core.persistence.StorageManager; import javax.transaction.xa.Xid; -/** - * Created by andy on 22/07/14. - */ public interface TransactionFactory { Transaction newTransaction(Xid xid, StorageManager storageManager, int timeoutSeconds); diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/network/MQTTNetworkOfBrokersFailoverTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/network/MQTTNetworkOfBrokersFailoverTest.java index 928a7a6364..d0bd3d79b9 100644 --- a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/network/MQTTNetworkOfBrokersFailoverTest.java +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/network/MQTTNetworkOfBrokersFailoverTest.java @@ -47,10 +47,6 @@ import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - * Created by ceposta - * filters) + { + StringWriter writer = new StringWriter(); + PrintWriter printWriter = new PrintWriter(writer); + printWriter.println(); + + for (String str : getQueueList()) + { + printWriter.println(" "); + } + for (String str : getTopicList()) + { + printWriter.println(" "); + } + filters.put("${jms-list.settings}", writer.toString()); + } + private void performAutoTune(HashMap filters, boolean aio, File dataFolder) { if (noAutoTune) @@ -793,6 +819,31 @@ public class Create extends InputAbstract } } + + private String[] getQueueList() + { + if (queues == null) + { + return new String[0]; + } + else + { + return queues.split(","); + } + } + + private String[] getTopicList() + { + if (topics == null) + { + return new String[0]; + } + else + { + return topics.split(","); + } + } + String path(String value, boolean unixPaths) throws IOException { return path(new File(value), unixPaths); diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/InputAbstract.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/InputAbstract.java index c348484dae..f5180ef17e 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/InputAbstract.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/InputAbstract.java @@ -26,7 +26,7 @@ public class InputAbstract extends ActionAbstract private Scanner scanner; - @Option(name = "--silent-input", description = "It will disable all the inputs, and it would make a best guess for any required input") + @Option(name = "--silent", description = "It will disable all the inputs, and it would make a best guess for any required input") private boolean silentInput = false; public boolean isSilentInput() diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/XmlDataExporter.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/XmlDataExporter.java index cf5be129ca..3ea76ce406 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/XmlDataExporter.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/XmlDataExporter.java @@ -131,7 +131,7 @@ public final class XmlDataExporter extends DataAbstract implements Action try { - process(System.out, getBinding(), getJournal(), getPaging(), getLargeMessages()); + process(context.out, getBinding(), getJournal(), getPaging(), getLargeMessages()); } catch (Exception e) { diff --git a/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/broker.xml b/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/broker.xml index 1cd32456e4..75cd6ee17e 100644 --- a/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/broker.xml +++ b/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/broker.xml @@ -24,7 +24,7 @@ under the License. - + ${jms-list.settings} diff --git a/artemis-cli/src/test/java/org/apache/activemq/cli/test/ArtemisTest.java b/artemis-cli/src/test/java/org/apache/activemq/cli/test/ArtemisTest.java index 3aed71e79e..a42fae92e7 100644 --- a/artemis-cli/src/test/java/org/apache/activemq/cli/test/ArtemisTest.java +++ b/artemis-cli/src/test/java/org/apache/activemq/cli/test/ArtemisTest.java @@ -23,9 +23,14 @@ import javax.jms.TextMessage; import java.io.File; import java.util.concurrent.TimeUnit; +import org.apache.activemq.artemis.api.core.SimpleString; +import org.apache.activemq.artemis.api.core.client.ClientSession; +import org.apache.activemq.artemis.api.core.client.ClientSessionFactory; +import org.apache.activemq.artemis.api.core.client.ServerLocator; import org.apache.activemq.artemis.cli.Artemis; import org.apache.activemq.artemis.cli.commands.Run; import org.apache.activemq.artemis.cli.commands.util.SyncCalculation; +import org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl; import org.apache.activemq.artemis.jlibaio.LibaioContext; import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; import org.apache.activemq.artemis.jms.client.ActiveMQDestination; @@ -83,15 +88,35 @@ public class ArtemisTest Assert.assertEquals(0, LibaioContext.getTotalMaxIO()); } - @Test public void testSimpleRun() throws Exception { + String queues = "q1,t2"; + String topics = "t1,t2"; Run.setEmbedded(true); - Artemis.main("create", temporaryFolder.getRoot().getAbsolutePath(), "--force", "--silent-input", "--no-web"); + Artemis.main("create", temporaryFolder.getRoot().getAbsolutePath(), "--force", "--silent", "--no-web", "--queues", queues, "--topics", topics); System.setProperty("artemis.instance", temporaryFolder.getRoot().getAbsolutePath()); // Some exceptions may happen on the initialization, but they should be ok on start the basic core protocol Artemis.execute("run"); + + + try (ServerLocator locator = ServerLocatorImpl.newLocator("tcp://localhost:61616"); + ClientSessionFactory factory = locator.createSessionFactory(); + ClientSession coreSession = factory.createSession()) + { + for (String str: queues.split(",")) + { + ClientSession.QueueQuery queryResult = coreSession.queueQuery(SimpleString.toSimpleString("jms.queue." + str)); + Assert.assertTrue("Couldn't find queue " + str, queryResult.isExists()); + } + for (String str: topics.split(",")) + { + ClientSession.QueueQuery queryResult = coreSession.queueQuery(SimpleString.toSimpleString("jms.topic." + str)); + Assert.assertTrue("Couldn't find topic " + str, queryResult.isExists()); + } + } + + Assert.assertEquals(Integer.valueOf(1000), Artemis.execute("producer", "--message-count", "1000", "--verbose")); Assert.assertEquals(Integer.valueOf(1000), Artemis.execute("consumer", "--verbose", "--break-on-null", "--receive-timeout", "100")); @@ -100,6 +125,7 @@ public class ArtemisTest Session session = connection.createSession(true, Session.SESSION_TRANSACTED); MessageProducer producer = session.createProducer(ActiveMQDestination.createDestination("queue://TEST", ActiveMQDestination.QUEUE_TYPE)); + TextMessage message = session.createTextMessage("Banana"); message.setStringProperty("fruit", "banana"); producer.send(message); diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/ActiveMQClientLogger.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/ActiveMQClientLogger.java index ba3fad85ff..8b3d0da9f2 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/ActiveMQClientLogger.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/ActiveMQClientLogger.java @@ -181,7 +181,7 @@ public interface ActiveMQClientLogger extends BasicLogger @Message(id = 212028, value = "error starting server locator", format = Message.Format.MESSAGE_FORMAT) void errorStartingLocator(@Cause Exception e); - @LogMessage(level = Logger.Level.WARN) + @LogMessage(level = Logger.Level.DEBUG) @Message(id = 212029, value = "Closing a Server Locator left open. Please make sure you close all Server Locators explicitly before letting them go out of scope! {0}", format = Message.Format.MESSAGE_FORMAT) diff --git a/artemis-distribution/src/main/resources/README.html b/artemis-distribution/src/main/resources/README.html index f8327061fa..fe89886b50 100644 --- a/artemis-distribution/src/main/resources/README.html +++ b/artemis-distribution/src/main/resources/README.html @@ -71,7 +71,7 @@ SYNOPSIS [--clustered] [--data ] [--encoding ] [--force] [--home ] [--host ] [--java-options ] [--password ] [--port-offset ] [--replicated] - [--role ] [--shared-store] [--silent-input] [--user ] [--] + [--role ] [--shared-store] [--silent] [--user ] [--] ... diff --git a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisAbstractPlugin.java b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisAbstractPlugin.java new file mode 100644 index 0000000000..43cc075a79 --- /dev/null +++ b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisAbstractPlugin.java @@ -0,0 +1,48 @@ +/** + * 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.maven; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Parameter; + +public abstract class ArtemisAbstractPlugin extends AbstractMojo +{ + + + /** It will ignore executioni if ignore has been set to true. This is useful as a property from the build. */ + @Parameter(defaultValue = "") + private boolean ignore; + + public void execute() throws MojoExecutionException, MojoFailureException + { + if (ignore) + { + getLog().debug("******************************************************************************************************"); + getLog().debug("Execution of " + getClass().getSimpleName() + " is being ignored as ignore has been set to true"); + getLog().debug("******************************************************************************************************"); + } + else + { + doExecute(); + } + } + + protected abstract void doExecute() throws MojoExecutionException, MojoFailureException; +} diff --git a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisCLIPlugin.java b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisCLIPlugin.java index 1fd46148db..45aafcb59b 100644 --- a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisCLIPlugin.java +++ b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisCLIPlugin.java @@ -16,10 +16,14 @@ */ 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 org.apache.activemq.artemis.cli.Artemis; import org.apache.activemq.artemis.cli.commands.Run; import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; -import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.descriptor.PluginDescriptor; @@ -28,13 +32,8 @@ 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 +public class ArtemisCLIPlugin extends ArtemisAbstractPlugin { private PluginDescriptor descriptor; @@ -98,7 +97,8 @@ public class ArtemisCLIPlugin extends AbstractMojo } - public void execute() throws MojoExecutionException, MojoFailureException + @Override + protected void doExecute() throws MojoExecutionException, MojoFailureException { // This is to avoid the Run issuing a kill at any point Run.setEmbedded(true); diff --git a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ActiveMQClientPlugin.java b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisClientPlugin.java similarity index 91% rename from artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ActiveMQClientPlugin.java rename to artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisClientPlugin.java index c269e4f691..1716c033d7 100644 --- a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ActiveMQClientPlugin.java +++ b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisClientPlugin.java @@ -16,21 +16,20 @@ */ package org.apache.activemq.artemis.maven; -import org.apache.maven.plugin.AbstractMojo; +import java.lang.reflect.Method; +import java.util.Properties; + import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; -import java.lang.reflect.Method; -import java.util.Properties; - /** * Allows a Java Client to be run which must hve a static main(String[] args) method */ @Mojo(name = "runClient", defaultPhase = LifecyclePhase.VERIFY) -public class ActiveMQClientPlugin extends AbstractMojo +public class ArtemisClientPlugin extends ArtemisAbstractPlugin { @Parameter @@ -44,7 +43,8 @@ public class ActiveMQClientPlugin extends AbstractMojo */ private Properties systemProperties; - public void execute() throws MojoExecutionException, MojoFailureException + @Override + protected void doExecute() throws MojoExecutionException, MojoFailureException { try { diff --git a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ActiveMQCreatePlugin.java b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisCreatePlugin.java similarity index 86% rename from artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ActiveMQCreatePlugin.java rename to artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisCreatePlugin.java index 405b2b1d80..eb3462ecac 100644 --- a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ActiveMQCreatePlugin.java +++ b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisCreatePlugin.java @@ -28,7 +28,6 @@ import java.util.Map; import java.util.Set; import org.apache.activemq.artemis.cli.Artemis; -import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.descriptor.PluginDescriptor; @@ -47,7 +46,7 @@ import org.eclipse.aether.resolution.ArtifactResolutionException; import org.eclipse.aether.resolution.ArtifactResult; @Mojo(name = "create", defaultPhase = LifecyclePhase.VERIFY) -public class ActiveMQCreatePlugin extends AbstractMojo +public class ArtemisCreatePlugin extends ArtemisAbstractPlugin { @@ -59,6 +58,7 @@ public class ActiveMQCreatePlugin extends AbstractMojo */ private PluginDescriptor descriptor; + /** Directory to replace the configuration with */ @Parameter(defaultValue = "${basedir}/target/classes/activemq/server0", required = true) private File configuration; @@ -98,7 +98,7 @@ public class ActiveMQCreatePlugin extends AbstractMojo @Parameter(defaultValue = "false") private boolean sharedStore; - @Parameter(defaultValue = "true") + @Parameter(defaultValue = "false") private boolean clustered; @Parameter(defaultValue = "false") @@ -110,6 +110,10 @@ public class ActiveMQCreatePlugin extends AbstractMojo @Parameter(defaultValue = "false") private boolean failoverOnShutdown; + /** it will disable auto-tune*/ + @Parameter(defaultValue = "true") + private boolean noAutoTune; + @Parameter(defaultValue = "ON_DEMAND") private String messageLoadBalancing; @@ -122,6 +126,13 @@ public class ActiveMQCreatePlugin extends AbstractMojo @Parameter(defaultValue = "${project.remoteProjectRepositories}") private List remoteRepos; + /** + * For extra stuff not covered by the properties + */ + @Parameter + ArrayList args = new ArrayList<>(); + + @Parameter private String[] libList; @@ -166,7 +177,8 @@ public class ActiveMQCreatePlugin extends AbstractMojo } } - public void execute() throws MojoExecutionException, MojoFailureException + @Override + protected void doExecute() throws MojoExecutionException, MojoFailureException { if (System.getProperty("bypassAddress") != null) { @@ -205,7 +217,8 @@ public class ActiveMQCreatePlugin extends AbstractMojo } ArrayList listCommands = new ArrayList<>(); - add(listCommands, "create", "--allow-anonymous", "--silent-input", "--force", "--no-web", "--user", user, "--password", password, + + add(listCommands, "create", "--allow-anonymous", "--silent", "--force", "--no-web", "--user", user, "--password", password, "--role", role, "--port-offset", "" + portOffset, "--data", dataFolder); @@ -250,38 +263,46 @@ public class ActiveMQCreatePlugin extends AbstractMojo add(listCommands, "--failover-on-shutdown"); } - add(listCommands, "--no-autotune"); + if (noAutoTune) + { + add(listCommands, "--no-autotune"); + } + add(listCommands, "--verbose"); + for (String str : args) + { + add(listCommands, str); + } + add(listCommands, instance.getAbsolutePath()); - getLog().info("************************************************"); - getLog().info("Calling create server at " + instance + " home= " + home); + getLog().debug("***** Server created at " + instance + " with home=" + home + " *****"); try { Artemis.execute(home, null, listCommands); - String[] list = configuration.list(); - - if (list != null) + if (configuration != null) { - getLog().debug("************************************************"); - getLog().debug("Replacing configuration files:"); + String[] list = configuration.list(); - for (String file : configuration.list()) + if (list != null) { - Path target = instance.toPath().resolve("etc").resolve(file); - getLog().debug("Replacing " + file + " into " + target); + getLog().debug("************************************************"); + getLog().debug("Replacing configuration files:"); + + for (String file : configuration.list()) + { + Path target = instance.toPath().resolve("etc").resolve(file); + getLog().debug("Replacing " + file + " into " + target); - Files.copy(configuration.toPath().resolve(file), target, StandardCopyOption.REPLACE_EXISTING); + Files.copy(configuration.toPath().resolve(file), target, StandardCopyOption.REPLACE_EXISTING); + } } } - File projectLib = project.getArtifact().getFile(); - copyToLib(projectLib); - if (libList != null) { for (int i = 0; i < libList.length; i++) diff --git a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/LibInstallPlugin.java b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/LibInstallPlugin.java deleted file mode 100644 index e65108d8d9..0000000000 --- a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/LibInstallPlugin.java +++ /dev/null @@ -1,147 +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. - */ -package org.apache.activemq.artemis.maven; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.StandardCopyOption; -import java.util.List; -import java.util.Map; - -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugin.descriptor.PluginDescriptor; -import org.apache.maven.plugins.annotations.Component; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.project.MavenProject; -import org.eclipse.aether.RepositorySystem; -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.artifact.DefaultArtifact; -import org.eclipse.aether.repository.RemoteRepository; -import org.eclipse.aether.resolution.ArtifactRequest; -import org.eclipse.aether.resolution.ArtifactResolutionException; -import org.eclipse.aether.resolution.ArtifactResult; - -@Mojo(name = "lib-install", defaultPhase = LifecyclePhase.VERIFY) -public class LibInstallPlugin extends AbstractMojo - -{ - - @Parameter - String name; - - /** - * The plugin descriptor - */ - private PluginDescriptor descriptor; - - @Parameter(defaultValue = "${basedir}/target/server0", required = true) - private File instance; - - @Component - private RepositorySystem repositorySystem; - - @Parameter(defaultValue = "${repositorySystemSession}") - private RepositorySystemSession repoSession; - - @Parameter(defaultValue = "${project.remoteProjectRepositories}") - private List remoteRepos; - - - @Parameter - private String[] libList; - - @Parameter(defaultValue = "${localRepository}") - private org.apache.maven.artifact.repository.ArtifactRepository localRepository; - - public void execute() throws MojoExecutionException, MojoFailureException - { - MavenProject project = (MavenProject) getPluginContext().get("project"); - - Map properties = getPluginContext(); - - try - { - - File projectLib = project.getArtifact().getFile(); - copyToLib(projectLib); - - if (libList != null) - { - for (int i = 0; i < libList.length; i++) - { - String[] splitString = libList[i].split(":"); - - getLog().info("********************" + splitString[0] + "/" + splitString[1] + "/" + splitString[2]); - - Artifact artifact; - try - { - artifact = new DefaultArtifact(libList[i]); - } - catch (IllegalArgumentException e) - { - throw new MojoFailureException(e.getMessage(), e); - } - - ArtifactRequest request = new ArtifactRequest(); - request.setArtifact(artifact); - request.setRepositories(remoteRepos); - - getLog().info("Resolving artifact " + artifact + " from " + remoteRepos); - - ArtifactResult result; - try - { - result = repositorySystem.resolveArtifact(repoSession, request); - } - catch (ArtifactResolutionException e) - { - throw new MojoExecutionException(e.getMessage(), e); - } - - File artifactFile = result.getArtifact().getFile(); - - getLog().info("Artifact:: " + artifact + " file = " + artifactFile); - - copyToLib(artifactFile); - - } - } - - } - catch (Exception e) - { - getLog().error(e); - throw new MojoFailureException(e.getMessage()); - } - } - - private void copyToLib(File projectLib) throws IOException - { - Path target = instance.toPath().resolve("lib").resolve(projectLib.getName()); - target.toFile().mkdirs(); - getLog().info("Copying " + projectLib.getName() + " as " + target.toFile().getAbsolutePath()); - Files.copy(projectLib.toPath(), target, StandardCopyOption.REPLACE_EXISTING); - } -} diff --git a/docs/user-manual/en/using-server.md b/docs/user-manual/en/using-server.md index 2fa214d5e3..9a59c29037 100644 --- a/docs/user-manual/en/using-server.md +++ b/docs/user-manual/en/using-server.md @@ -93,7 +93,7 @@ For a full list of updated properties always use: [--clustered] [--data ] [--encoding ] [--force] [--home ] [--host ] [--java-options ] [--password ] [--port-offset ] [--replicated] - [--role ] [--shared-store] [--silent-input] [--user ] [--] + [--role ] [--shared-store] [--silent] [--user ] [--] OPTIONS @@ -143,7 +143,7 @@ For a full list of updated properties always use: --shared-store Enable broker shared store - --silent-input + --silent It will disable all the inputs, and it would make a best guess for any required input diff --git a/examples/core/embedded/pom.xml b/examples/core/embedded/pom.xml index 8453105cf4..ebe5254308 100644 --- a/examples/core/embedded/pom.xml +++ b/examples/core/embedded/pom.xml @@ -61,9 +61,6 @@ under the License. - - - example @@ -84,6 +81,4 @@ under the License. - - diff --git a/examples/core/embedded/readme.html b/examples/core/embedded/readme.html index c5c21418ba..d65caa220c 100644 --- a/examples/core/embedded/readme.html +++ b/examples/core/embedded/readme.html @@ -38,7 +38,7 @@ under the License.

ActiveMQ Artemis Embedded could be used from very simple use cases with only InVM support to very complex cases with clustering, persistence and fail over.

Example step-by-step

-

To run the example, simply type mvn verify -Pexample from this directory

+

To run the example, simply type mvn verify from this directory

In this we don't use any configuration files. (Everything is embedded). We simply instantiate ConfigurationImpl, ActiveMQServer, start it and operate on JMS regularly

    diff --git a/examples/core/perf/src/main/resources/activemq/server0/broker.xml b/examples/core/perf/src/main/resources/activemq/server0/broker.xml index 8876d42c49..6e787fb84d 100644 --- a/examples/core/perf/src/main/resources/activemq/server0/broker.xml +++ b/examples/core/perf/src/main/resources/activemq/server0/broker.xml @@ -23,13 +23,13 @@ under the License. xsi:schemaLocation="urn:activemq /schema/artemis-server.xsd"> - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/core/pom.xml b/examples/core/pom.xml index c88656e855..fd3ba183e8 100644 --- a/examples/core/pom.xml +++ b/examples/core/pom.xml @@ -39,7 +39,8 @@ under the License. - release + + examples embedded embedded-remote diff --git a/examples/jms/README.md b/examples/jms/README.md index f0cd2af3ef..e9d9e36112 100644 --- a/examples/jms/README.md +++ b/examples/jms/README.md @@ -3,22 +3,25 @@ Running the ActiveMQ Artemis Examples To run an individual example firstly cd into the example directory and run +```sh +mvn verify ``` -mvn verify -Pexample + +Most examples offer a way to start them without creating and starting the server (say if you want to do it manually) + +```sh +mvn verify -PnoServer ``` If you are running against an un released version, i.e. from master branch, you will have to run `mvn install` on the root pom.xml and the example/activemq-jms-examples-common/pom.xml first. -If you want to run all the examples (except those that need to be run standalone) you can run `mvn verify -Pexample` in the examples +If you want to run all the examples (except those that need to be run standalone) you can run `mvn verify -Pexamples` in the examples directory but before you do you will need to up the memory used by running: ``` export MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=256m" ``` - -To run the javaee examples follow the instructions in examples/javaee/README.md - ### Recreating the examples If you are trying to copy the examples somewhere else and modifying them. Consider asking Maven to explicitly list all the dependencies: diff --git a/examples/jms/aerogear/pom.xml b/examples/jms/aerogear/pom.xml index a42a6e889c..fc224d623a 100644 --- a/examples/jms/aerogear/pom.xml +++ b/examples/jms/aerogear/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -34,7 +35,7 @@ under the License. ${project.basedir}/../../.. - artemis-jms-aerogear-example + aerogear jar ActiveMQ Artemis JMS AeroGear Example @@ -48,80 +49,86 @@ under the License. - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - - - org.apache.activemq:artemis-aerogear-integration:${project.version} - org.jboss.aerogear:unifiedpush-java-client:1.0.0 - net.iharder:base64:2.3.8 - com.fasterxml.jackson.core:jackson-annotations:2.3.0 - com.fasterxml.jackson.core:jackson-core:2.3.0 - org.jboss.resteasy:resteasy-jackson-provider:2.3.2.Final - org.codehaus.jackson:jackson-core-asl:1.8.5 - org.codehaus.jackson:jackson-mapper-asl:1.8.5 - org.codehaus.jackson:jackson-jaxrs:1.8.5 - org.codehaus.jackson:jackson-xc:1.8.5 - - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.AerogearExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-aerogear-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + + org.apache.activemq:artemis-aerogear-integration:${project.version} + org.jboss.aerogear:unifiedpush-java-client:1.0.0 + net.iharder:base64:2.3.8 + com.fasterxml.jackson.core:jackson-annotations:2.3.0 + com.fasterxml.jackson.core:jackson-core:2.3.0 + org.jboss.resteasy:resteasy-jackson-provider:2.3.2.Final + org.codehaus.jackson:jackson-core-asl:1.8.5 + org.codehaus.jackson:jackson-mapper-asl:1.8.5 + org.codehaus.jackson:jackson-jaxrs:1.8.5 + org.codehaus.jackson:jackson-xc:1.8.5 + + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.AerogearExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + aerogear + ${project.version} + + + + + diff --git a/examples/jms/aerogear/readme.html b/examples/jms/aerogear/readme.html index 661b7d14f5..bdddfa65c3 100644 --- a/examples/jms/aerogear/readme.html +++ b/examples/jms/aerogear/readme.html @@ -27,6 +27,9 @@ under the License.

    JMS AeroGear Example

    + +
    To run the example, simply type mvn verify from this directory, 
    or mvn -PnoServer verify if you want to start and create the server manually.
    +

    This example shows how you can send a message to a mobile device by leveraging AeroGears push technology which provides support for different push notification technologies like Google Cloud Messaging, Apple's APNs or Mozilla's SimplePush.

    diff --git a/examples/jms/aerogear/src/main/resources/activemq/server0/broker.xml b/examples/jms/aerogear/src/main/resources/activemq/server0/broker.xml index 5c389c8ac5..1095761a10 100644 --- a/examples/jms/aerogear/src/main/resources/activemq/server0/broker.xml +++ b/examples/jms/aerogear/src/main/resources/activemq/server0/broker.xml @@ -29,13 +29,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/application-layer-failover/pom.xml b/examples/jms/application-layer-failover/pom.xml index 65d217d75a..b670d1858c 100644 --- a/examples/jms/application-layer-failover/pom.xml +++ b/examples/jms/application-layer-failover/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-application-layer-failover-example + application-layer-failover jar ActiveMQ Artemis JMS Application Layer Failover Example @@ -42,64 +43,60 @@ under the License. ${project.version} - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - - - example - - - - org.apache.activemq - artemis-maven-plugin - - - create0 - - create - - - ${basedir}/target/server0 - - - - create1 - - create - - - ${basedir}/target/server1 - 1 - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.ApplicationLayerFailoverExample - - ${basedir}/target/server0 - ${basedir}/target/server1 - - - - - - - org.apache.activemq.examples.jms - artemis-jms-application-layer-failover-example - ${project.version} - - - - - - - + + + + org.apache.activemq + artemis-maven-plugin + + + create0 + + create + + + ${basedir}/target/server0 + + + + create1 + + create + + + ${basedir}/target/server1 + 1 + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.ApplicationLayerFailoverExample + + ${basedir}/target/server0 + ${basedir}/target/server1 + + + + + + + org.apache.activemq.examples.jms + application-layer-failover + ${project.version} + + + + + diff --git a/examples/jms/application-layer-failover/readme.html b/examples/jms/application-layer-failover/readme.html index b9699bc7dd..3a23b62926 100644 --- a/examples/jms/application-layer-failover/readme.html +++ b/examples/jms/application-layer-failover/readme.html @@ -27,6 +27,8 @@ under the License.

    Application-Layer Failover Example

    +
    To run the example, simply type mvn verify from this directory. This example will always spawn and stop multiple servers.
    +

    ActiveMQ Artemis implements fully transparent automatic failover of connections from a live node to a backup node which requires no special coding. This is described in a different example and requires server replication.

    However, ActiveMQ Artemis also supports Application-Layer failover which is useful in the case where replication is not enabled.

    @@ -37,12 +39,11 @@ under the License.

    Application-Layer failover is an alternative approach to High Availabilty (HA).

    Application-Layer failover differs from automatic failover in that some client side coding is required in order to implement this. Also, with Application-Layer failover, since the old Session object dies and a new is created, any uncommitted - work in the old Session will be lost, and any unacknowledged messages might be redelivered.

    + work in the old Session will be lost, and any unacknowledged messages might be redelivered.

    For more information on ActiveMQ Artemis failover and HA, and clustering in general, please see the clustering - section of the user manual.

    + section of the user manual.

    Example step-by-step

    -

    To run the example, simply type mvn verify -Pexample from this directory

    In this example, the live server is server 1, which will failover onto server 0.

    The connection will initially be created to server1, server 1 will crash, and the client will carry on on server 0, the new server. With Application-Layer failover the node that is failed over onto, does not need to @@ -87,13 +88,13 @@ under the License. } - +

  1. We now cause server 1, the live server to crash. After a little while the connection's ExceptionListener will register the failure and reconnection will occur.
  2.             killServer(1);
             
    - +
  3. The connection's ExceptionListener gets called, and we lookup the JMS objects and recreate the connection, session, etc on the other node 0.
  4. @@ -121,7 +122,7 @@ under the License.
                 e.printStackTrace();
              }
           }
    -   }   
    +   }
                
             
    @@ -138,7 +139,7 @@ under the License. } - +
  5. And consume them.
  6.             
    diff --git a/examples/jms/application-layer-failover/src/main/java/org/apache/activemq/artemis/jms/example/ApplicationLayerFailoverExample.java b/examples/jms/application-layer-failover/src/main/java/org/apache/activemq/artemis/jms/example/ApplicationLayerFailoverExample.java
    index fcd3ccaaaf..86a23390e0 100644
    --- a/examples/jms/application-layer-failover/src/main/java/org/apache/activemq/artemis/jms/example/ApplicationLayerFailoverExample.java
    +++ b/examples/jms/application-layer-failover/src/main/java/org/apache/activemq/artemis/jms/example/ApplicationLayerFailoverExample.java
    @@ -16,14 +16,6 @@
      */
     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;
    -import java.util.concurrent.CountDownLatch;
    -import java.util.concurrent.TimeUnit;
    -
     import javax.jms.Connection;
     import javax.jms.ConnectionFactory;
     import javax.jms.ExceptionListener;
    @@ -35,6 +27,11 @@ import javax.jms.Session;
     import javax.jms.TextMessage;
     import javax.naming.InitialContext;
     import javax.naming.NamingException;
    +import java.util.concurrent.CountDownLatch;
    +import java.util.concurrent.TimeUnit;
    +
    +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
    +import org.apache.activemq.artemis.util.ServerUtil;
     
     /**
      * A simple example that demonstrates application-layer failover of the JMS connection from one node to another
    @@ -144,32 +141,25 @@ public class ApplicationLayerFailoverExample
     
        private static void createJMSObjects(final int server) throws Exception
        {
    -      // Step 1. Get an initial context for looking up JNDI from the server
    -      Hashtable properties = new Hashtable();
    -      properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
    -      properties.put("connectionFactory.ConnectionFactory", "tcp://127.0.0.1:" + (61616 + server));
    -      properties.put("queue.queue/exampleQueue", "exampleQueue");
    -      initialContext = new InitialContext(properties);
    +      // Step 1. Instantiate a JMS Connection Factory object from JNDI on server 1
    +      ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://127.0.0.1:" + (61616 + server));
     
    -      // Step 2. Look-up the JMS Queue object from JNDI
    -      Queue queue = (Queue)initialContext.lookup("queue/exampleQueue");
    -
    -      // Step 3. Look-up a JMS Connection Factory object from JNDI on server 1
    -      ConnectionFactory connectionFactory = (ConnectionFactory)initialContext.lookup("ConnectionFactory");
    -
    -      // Step 4. We create a JMS Connection connection
    +      // Step 2. We create a JMS Connection connection
           connection = connectionFactory.createConnection();
     
    -      // Step 6. We start the connection to ensure delivery occurs
    +      // Step 3. We start the connection to ensure delivery occurs
           connection.start();
     
    -      // Step 5. We create a JMS Session
    +      // Step 4. We create a JMS Session
           session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
     
    -      // Step 7. We create a JMS MessageConsumer object
    +      // Step 5. Look-up the JMS Queue object from JNDI
    +      Queue queue = session.createQueue("exampleQueue");
    +
    +      // Step 6. We create a JMS MessageConsumer object
           consumer = session.createConsumer(queue);
     
    -      // Step 8. We create a JMS MessageProducer object
    +      // Step 7. We create a JMS MessageProducer object
           producer = session.createProducer(queue);
        }
     
    diff --git a/examples/jms/bridge/pom.xml b/examples/jms/bridge/pom.xml
    index 73cbdc56d9..8c835de0cf 100644
    --- a/examples/jms/bridge/pom.xml
    +++ b/examples/jms/bridge/pom.xml
    @@ -18,7 +18,8 @@ specific language governing permissions and limitations
     under the License.
     -->
     
    -
    +
        4.0.0
     
        
    @@ -27,7 +28,7 @@ under the License.
           1.0.1-SNAPSHOT
        
     
    -   artemis-jms-core-bridge-example
    +   core-bridge
        jar
        ActiveMQ Artemis Core Bridge Example
     
    @@ -49,109 +50,127 @@ under the License.
     
        
           
    -         example
    -         
    -            
    -               
    -                  org.apache.activemq
    -                  artemis-maven-plugin
    -                  
    -                     
    -                        create0
    -                        
    -                           create
    -                        
    -                        
    -                           ${basedir}/target/server0
    -                           ${basedir}/target/classes/activemq/server0
    -                        
    -                     
    -                     
    -                        create1
    -                        
    -                           create
    -                        
    -                        
    -                           ${basedir}/target/server1
    -                           ${basedir}/target/classes/activemq/server1
    -                           1
    -                        
    -                     
    -                     
    -                        start0
    -                        
    -                           cli
    -                        
    -                        
    -                           true
    -                           ${basedir}/target/server0
    -                           tcp://localhost:61616
    -                           
    -                              run
    -                           
    -                           server0
    -                        
    -                     
    -                     
    -                        start1
    -                        
    -                           cli
    -                        
    -                        
    -                           true
    -                           ${basedir}/target/server1
    -                           tcp://localhost:61617
    -                           
    -                              run
    -                           
    -                           server1
    -                        
    -                     
    -                     
    -                        runClient
    -                        
    -                           runClient
    -                        
    -                        
    -                           org.apache.activemq.artemis.jms.example.BridgeExample
    -                        
    -                     
    -                     
    -                        stop0
    -                        
    -                           cli
    -                        
    -                        
    -                           ${basedir}/target/server0
    -                           
    -                              stop
    -                           
    -                        
    -                     
    -                     
    -                        stop1
    -                        
    -                           cli
    -                        
    -                        
    -                           ${basedir}/target/server1
    -                           
    -                              stop
    -                           
    -                        
    -                     
    -                  
    -                  
    -                     
    -                        org.apache.activemq.examples.jms
    -                        artemis-jms-core-bridge-example
    -                        ${project.version}
    -                     
    -                  
    -               
    -            
    -         
    +         
    +         noServer
    +         
    +            true
    +         
           
        
    +   
    +      
    +         
    +            org.apache.activemq
    +            artemis-maven-plugin
    +            
    +               
    +                  create0
    +                  
    +                     create
    +                  
    +                  
    +                     
    +                        
    +                        org.apache.activemq.examples.jms:core-bridge:${project.version}
    +                     
    +                     ${noServer}
    +                     ${basedir}/target/server0
    +                     ${basedir}/target/classes/activemq/server0
    +                  
    +               
    +               
    +                  create1
    +                  
    +                     create
    +                  
    +                  
    +                     
    +                        
    +                        org.apache.activemq.examples.jms:core-bridge:${project.version}
    +                     
    +                     ${noServer}
    +                     ${basedir}/target/server1
    +                     ${basedir}/target/classes/activemq/server1
    +                     1
    +                  
    +               
    +               
    +                  start0
    +                  
    +                     cli
    +                  
    +                  
    +                     ${noServer}
    +                     true
    +                     ${basedir}/target/server0
    +                     tcp://localhost:61616
    +                     
    +                        run
    +                     
    +                     server0
    +                  
    +               
    +               
    +                  start1
    +                  
    +                     cli
    +                  
    +                  
    +                     ${noServer}
    +                     true
    +                     ${basedir}/target/server1
    +                     tcp://localhost:61617
    +                     
    +                        run
    +                     
    +                     server1
    +                  
    +               
    +               
    +                  runClient
    +                  
    +                     runClient
    +                  
    +                  
    +                     org.apache.activemq.artemis.jms.example.BridgeExample
    +                  
    +               
    +               
    +                  stop0
    +                  
    +                     cli
    +                  
    +                  
    +                     ${noServer}
    +                     ${basedir}/target/server0
    +                     
    +                        stop
    +                     
    +                  
    +               
    +               
    +                  stop1
    +                  
    +                     cli
    +                  
    +                  
    +                     ${noServer}
    +                     ${basedir}/target/server1
    +                     
    +                        stop
    +                     
    +                  
    +               
    +            
    +            
    +               
    +                  org.apache.activemq.examples.jms
    +                  core-bridge
    +                  ${project.version}
    +               
    +            
    +         
    +      
    +   
     
     
    diff --git a/examples/jms/bridge/readme.html b/examples/jms/bridge/readme.html
    index 6b5bb01c03..a9440c792f 100644
    --- a/examples/jms/bridge/readme.html
    +++ b/examples/jms/bridge/readme.html
    @@ -26,6 +26,7 @@ under the License.
       
       
          

    Core Bridge Example

    +
    To run the example, simply type mvn verify from this directory, 
    or mvn -PnoServer verify if you want to start and create the server manually.

    This example demonstrates a core bridge deployed on one server, which consumes messages from a local queue and forwards them to an address on a second server.

    @@ -69,166 +70,5 @@ under the License. </bridge>
    -

    Example step-by-step

    -

    To run the example, simply type mvn verify -Pexample from this directory

    - -
      -
    1. We create an initial context for looking up JNDI on node 0
    2. -
      -           
      -   ic0 = getContext(0);
      -   
      -        
      - -
    3. We look up the sausage-factory queue from node 0
    4. -
      -           Queue sausageFactory = (Queue)ic0.lookup("/queue/sausage-factory");
      -        
      - -
    5. We look up a JMS ConnectionFactory object from node 0
    6. -
      -           ConnectionFactory cf0 = (ConnectionFactory)ic0.lookup("/ConnectionFactory");
      -        
      - -
    7. We create an initial context for looking up JNDI on node 1
    8. -
      -           ic1 = getContext(1);
      -        
      - -
    9. We look up the mincing-machine queue on node 1
    10. -
      -           Queue mincingMachine = (Queue)ic1.lookup("/queue/mincing-machine");
      -           
      -        
      - -
    11. We look up a JMS ConnectionFactory object from node 1
    12. -
      -          
      -   ConnectionFactory cf1 = (ConnectionFactory)ic1.lookup("/ConnectionFactory");
      -          
      -        
      - -
    13. We create a JMS Connection connection0 which is a connection to server 0
    14. -
      -          
      -   connection0 = cf0.createConnection();
      -          
      -        
      - -
    15. We create a JMS Connection connection1 which is a connection to server 1
    16. -
      -          
      -   connection1 = cf1.createConnection();
      -          
      -        
      - -
    17. We create a JMS Session on server 0
    18. -
      -           
      -   Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE);
      -           
      -        
      - -
    19. We create a JMS Session on server 1
    20. -
      -           
      -   Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
      -            
      -        
      - -
    21. We start the connection to ensure delivery occurs on them
    22. -
      -           
      -   connection1.start();
      -           
      -        
      - -
    23. We create a JMS MessageConsumer object on server 1
    24. -
      -           
      -   MessageConsumer consumer = session1.createConsumer(mincingMachine);
      -           
      -        
      - -
    25. We create a JMS MessageProducer object on server 0.
    26. -
      -           
      -   MessageProducer producer = session0.createProducer(sausageFactory);
      -        
      - -
    27. We create and send a message representing an aardvark with a green hat to the sausage-factory - on node 0
    28. -
      -           
      -         Message message = session0.createMessage();
      -
      -         message.setStringProperty("name", "aardvark");
      -
      -         message.setStringProperty("hat", "green");
      -
      -         producer.send(message);
      -           
      -        
      - -
    29. 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!
    30. -
      -           
      -        Message receivedMessage = consumer.receive(5000);
      -           
      -        
      - -
    31. 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 sasquatches.
    32. -
      -           
      -         message = session0.createMessage();
      -
      -         message.setStringProperty("name", "sasquatch");
      -
      -         message.setStringProperty("hat", "mauve");
      -
      -         producer.send(message);
      -           
      -        
      - -
    33. We don't receive the sasquatch message since it's not an aardvark!
    34. -
      -           
      -         receivedMessage = (TextMessage)consumer.receive(1000);
      -           
      -        
      - - -
    35. And finally (no pun intended), always remember to close your JMS resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
    36. - -
      -           
      -	finally
      -	{
      -	      if (connection0 != null)
      -         {
      -            connection0.close();
      -         }
      -
      -         if (connection1 != null)
      -         {
      -            connection1.close();
      -         }
      -
      -         if (ic0 != null)
      -         {
      -            ic0.close();
      -         }
      -
      -         if (ic1 != null)
      -         {
      -            ic1.close();
      -         }
      -	}
      -           
      -        
      - -
    diff --git a/examples/jms/browser/pom.xml b/examples/jms/browser/pom.xml index adaf22266d..8cbd2d7392 100644 --- a/examples/jms/browser/pom.xml +++ b/examples/jms/browser/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-browser-example + browser jar ActiveMQ Artemis JMS Browser Example @@ -37,72 +38,82 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - verify - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.QueueBrowserExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-browser-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + verify + + ${noServer} + + + create + + + + start + + cli + + + true + ${noServer} + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.QueueBrowserExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + browser + ${project.version} + + + + + diff --git a/examples/jms/browser/readme.html b/examples/jms/browser/readme.html index b960ff4115..76f349f97e 100644 --- a/examples/jms/browser/readme.html +++ b/examples/jms/browser/readme.html @@ -26,122 +26,15 @@ under the License.

    JMS QueueBrowser Example

    +
    To run the example, simply type mvn verify from this directory, 
    or mvn -PnoServer verify if you want to start and create the server manually.

    This example shows you how to use a JMS QueueBrowser with ActiveMQ Artemis.
    Queues are a standard part of JMS, please consult the JMS 1.1 specification for full details.
    - A QueueBrowser is used to look at messages on the queue without removing them. + A QueueBrowser is used to look at messages on the queue without removing them. It can scan the entire content of a queue or only messages matching a message selector.

    - The example will send 2 messages on a queue, use a QueueBrowser to browse + The example will send 2 messages on a queue, use a QueueBrowser to browse the queue (looking at the message without removing them) and finally consume the 2 messages

    -

    Example step-by-step

    -

    To run the example, simply type mvn verify -Pexample from this directory

    - -
      -
    1. First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the client-jndi.properties file in the directory ../common/config
    2. -
      -           InitialContext initialContext = getContext();
      -        
      - -
    3. We look up the JMS queue object from JNDI
    4. -
      -           Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");
      -        
      - -
    5. We look up the JMS connection factory object from JNDI
    6. -
      -           ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
      -        
      - -
    7. We create a JMS connection
    8. -
      -           connection = cf.createConnection();
      -        
      - -
    9. We create a JMS session. The session is created as non transacted and will auto acknowledge messages.
    10. -
      -           Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      -        
      - -
    11. We create a JMS message producer on the session. This will be used to send the messages.
    12. -
      -          MessageProducer messageProducer = session.createProducer(topic);
      -       
      - -
    13. We create 2 JMS text messages that we are going to send.
    14. -
      -            TextMessage message_1 = session.createTextMessage("this is the 1st message");
      -            TextMessage message_2 = session.createTextMessage("this is the 2nd message");
      -        
      - -
    15. We send messages to the queue
    16. -
      -           messageProducer.send(message_1);
      -           messageProducer.send(message_2);
      -        
      - -
    17. We create a JMS QueueBrowser.
      - We have not specified a message selector so the browser will enumerate the entire content of the queue. -
    18. -
      -           QueueBrowser browser = session.createBrowser(queue);
      -        
      - -
    19. We browse the queue and display all the messages' text -
    20. -
      -            Enumeration messageEnum = browser.getEnumeration();
      -            while (messageEnum.hasMoreElements())
      -            {
      -               TextMessage message = (TextMessage)messageEnum.nextElement();
      -               System.out.println("Browsing: " + message.getText());
      -            }
      -        
      - -
    21. We close the browser once we have finished to use it
    22. -
      -            browser.close();
      -        
      - -

      The messages were browsed but they were not removed from the queue. We will now consume them.

      - -
    23. We create a JMS Message Consumer to receive the messages.
    24. -
      -           MessageConsumer messageConsumer = session.createConsumer(queue);
      -        
      - -
    25. We start the connection. In order for delivery to occur on any consumers or subscribers on a connection, the connection must be started
    26. -
      -           connection.start();
      -        
      - -
    27. The 2 messages arrive at the consumer
    28. -
      -           TextMessage messageReceived = (TextMessage)messageConsumer.receive(5000);
      -           System.out.println("Received message: " + messageReceived.getText());
      -           messageReceived = (TextMessage)messageConsumer.receive(5000);
      -           System.out.println("Received message: " + messageReceived.getText());
      -        
      - -
    29. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
    30. - -
      -           finally
      -           {
      -              if (initialContext != null)
      -              {
      -                initialContext.close();
      -              }
      -              if (connection != null)
      -              {
      -                 connection.close();
      -              }
      -           }
      -        
      - - - -
    diff --git a/examples/jms/browser/src/main/java/org/apache/activemq/artemis/jms/example/QueueBrowserExample.java b/examples/jms/browser/src/main/java/org/apache/activemq/artemis/jms/example/QueueBrowserExample.java index 6c93cc685a..d7f060c830 100644 --- a/examples/jms/browser/src/main/java/org/apache/activemq/artemis/jms/example/QueueBrowserExample.java +++ b/examples/jms/browser/src/main/java/org/apache/activemq/artemis/jms/example/QueueBrowserExample.java @@ -45,8 +45,11 @@ public class QueueBrowserExample Queue queue = (Queue)initialContext.lookup("queue/exampleQueue"); // Step 3. Perform a lookup on the Connection Factory + // you could alternatively instantiate the connection directly + // ConnectionFactory cf = new ActiveMQConnectionFactory(); // this would accept the broker URI as well ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("ConnectionFactory"); + // Step 4. Create a JMS Connection connection = cf.createConnection(); diff --git a/examples/jms/client-kickoff/pom.xml b/examples/jms/client-kickoff/pom.xml index 1c86b5a520..a07eb3546d 100644 --- a/examples/jms/client-kickoff/pom.xml +++ b/examples/jms/client-kickoff/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-client-kickoff-example + client-kickoff jar ActiveMQ Artemis JMS Kick Off Example @@ -38,79 +39,84 @@ under the License. org.apache.activemq - artemis-core-client + artemis-jms-client ${project.version} - - org.apache.geronimo.specs - geronimo-jms_2.0_spec - - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=3000 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.ClientKickoffExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-client-kickoff-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=3000 + -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false + + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.ClientKickoffExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + client-kickoff + ${project.version} + + + + + diff --git a/examples/jms/client-kickoff/readme.html b/examples/jms/client-kickoff/readme.html index f30598a6d0..064f7fbb45 100644 --- a/examples/jms/client-kickoff/readme.html +++ b/examples/jms/client-kickoff/readme.html @@ -27,6 +27,8 @@ under the License.

    Client Kickoff Example

    +
    To run the example, simply type mvn verify from this directory, 
    or mvn -PnoServer verify if you want to start and create the server manually.
    +

    This example shows how to kick off a client connected to ActiveMQ using JMX

    @@ -48,109 +50,5 @@ under the License. (please note that for this example, we will disable user authentication for simplicity).

    With these properties, ActiveMQ Artemis server will be manageable remotely using standard JMX URL on port 3000.

    - -

    Example step-by-step

    -

    To run the example, simply type mvn verify -Pexample from this directory

    -
      -
    1. First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get its properties from client-jndi.properties
    2. -
      -            InitialContext initialContext = getContext(0);
      -        
      - -
    3. We look up the JMS connection factory object from JNDI
    4. -
      -            ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
      -        
      - -
    5. We create a JMS connection
    6. -
      -            connection = cf.createConnection();
      -        
      - -
    7. We set a ExceptionListener on the connection to be notified after a problem occurred
    8. -
      -            final AtomicReference<JMSException> exception = new AtomicReference<JMSException>();
      -            connection.setExceptionListener(new ExceptionListener()
      -            {
      -               public void onException(JMSException e)
      -               {
      -                  exception.set(e);
      -               }
      -            });
      -        
      - -
    9. We start the connection
    10. -
      -            connection.start();
      -       
      - -
    11. We create a MBean proxy to the ActiveMQServerControlMBean used to manage ActiveMQ Artemis server - (see JMX example for a complete explanation of the different steps)
    12. -
      -            ObjectName on = ObjectNameBuilder.DEFAULT.getActiveMQServerObjectName();
      -            JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(JMX_URL), new HashMap());
      -            MBeanServerConnection mbsc = connector.getMBeanServerConnection();
      -            ActiveMQServerControlMBean serverControl = (ActiveMQServerControlMBean)MBeanServerInvocationHandler.newProxyInstance(mbsc,
      -                                                                                                on,
      -                                                                                                ActiveMQServerControlMBean.class,
      -                                                                                                false);
      -            
      -        
      - -
    13. Using the server MBean, we list the remote address connected to the server
    14. -
      -            String[] remoteAddresses = serverControl.listRemoteAddresses();
      -            for (String remoteAddress : remoteAddresses)
      -            {
      -               System.out.println(remoteAddress);
      -            }
      -            
      -        
      - -

      It will display a single address corresponding to the connection opened at step 3.

      - -
    15. We close the connections corresponding to this remote address
    16. -
      -              serverControl.closeConnectionsForAddress(remoteAddresses[0]);
      -        
      - -

      Warnings be displayed on the server output:

      -
      -            org.apache.activemq.artemis.jms.example.SpawnedJMSServer out:11:22:33,034 WARN  @RMI TCP Connection(3)-192.168.0.10 [RemotingConnectionImpl] Connection failure has been detected connections for /192.168.0.10:52707 closed by management:0
      -            org.apache.activemq.artemis.jms.example.SpawnedJMSServer out:11:22:33,035 WARN  @RMI TCP Connection(3)-192.168.0.10 [ServerSessionImpl] Client connection failed, clearing up resources for session 4646da35-2fe8-11de-9ce9-752ccc2b26e4
      -            org.apache.activemq.artemis.jms.example.SpawnedJMSServer out:11:22:33,035 WARN  @RMI TCP Connection(3)-192.168.0.10 [ServerSessionImpl] Cleared up resources for session 4646da35-2fe8-11de-9ce9-752ccc2b26e4
      -            
      -        
      - -
    17. We display the exception received by the connection's ExceptionListener
    18. -
      -            exception.get().printStackTrace();
      -        
      - -

      When the connection was closed on the server-side by the call to serverControl.closeConnectionsForAddress(), - the client's connection was disconnected and its exception listener was notified.

      - -
    19. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
    20. - -
      -           finally
      -           {
      -              if (initialContext != null)
      -              {
      -                initialContext.close();
      -              }
      -              if (connection != null)
      -              {
      -                 connection.close();
      -              }
      -           }
      -        
      -
    - -

    More information

    - - diff --git a/examples/jms/client-side-failoverlistener/pom.xml b/examples/jms/client-side-failoverlistener/pom.xml index cfdcdd6181..4f5eaa5192 100644 --- a/examples/jms/client-side-failoverlistener/pom.xml +++ b/examples/jms/client-side-failoverlistener/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-client-side-fileoverlistener-example + client-side-fileoverlistener jar ActiveMQ Artemis JMS Client Side Failover listener Example @@ -46,72 +47,63 @@ under the License. artemis-jms-client ${project.version} - - org.apache.geronimo.specs - geronimo-jms_2.0_spec - - - - example - - - - org.apache.activemq - artemis-maven-plugin - - - create0 - - create - - - ${basedir}/target/server0 - ../shared - true - false - true - - - - create1 - - create - - - ${basedir}/target/server1 - ../shared - true - true - 1 - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.ClientSideFailoverListerExample - - ${basedir}/target/server0 - ${basedir}/target/server1 - - - - - - - org.apache.activemq.examples.jms - artemis-jms-client-side-fileoverlistener-example - ${project.version} - - - - - - - + + + + org.apache.activemq + artemis-maven-plugin + + + create0 + + create + + + ${basedir}/target/server0 + ../shared + true + false + true + + + + create1 + + create + + + ${basedir}/target/server1 + ../shared + true + true + 1 + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.ClientSideFailoverListerExample + + ${basedir}/target/server0 + ${basedir}/target/server1 + + + + + + + org.apache.activemq.examples.jms + client-side-fileoverlistener + ${project.version} + + + + + diff --git a/examples/jms/client-side-failoverlistener/readme.html b/examples/jms/client-side-failoverlistener/readme.html index c58abc68e7..9f718930e8 100644 --- a/examples/jms/client-side-failoverlistener/readme.html +++ b/examples/jms/client-side-failoverlistener/readme.html @@ -26,88 +26,12 @@ under the License.

    Client Side Kickoff Example

    +
    To run the example, simply type mvn verify from this directory. This example will always spawn and stop multiple servers.

    This example demonstrates how you can listen on failover event on the client side.

    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.

    - -

    Example step-by-step

    -

    To run the example, simply type mvn verify -Pexample from this directory

    -
      -
    1. First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get its properties from client-jndi.properties
    2. -
      -            InitialContext initialContext = getContext(0);
      -        
      -
    3. We look up the JMS Queue object from JNDI
    4. -
      -            Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue");
      -        
      - -
    5. We look up a JMS Connection Factory object from JNDI on server 0
    6. -
      -            ConnectionFactory connectionFactory = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
      -        
      - -
    7. We create a JMS connection from the same connection factory, wait a little while to make sure broadcasts from all nodes have reached the client
    8. -
      -            
      -            Thread.sleep(5000);
      -            connectionA = connectionFactory.createConnection();
      -            ((ActiveMQConnection)connectionA).setFailoverListener(new FailoverListenerImpl());
      -			
      -        
      - -
    9. We create JMS Sessions
    10. -
      -            Session sessionA = connectionA.createSession(false, Session.AUTO_ACKNOWLEDGE);
      -       
      - -
    11. We create JMS MessageProducer objects on the sessions
    12. -
      -            MessageProducer producerA = sessionA.createProducer(queue);
      -        
      - -
    13. We send some messages on each producer
    14. -
      -            
      -            final int numMessages = 10;
      -
      -            for (int i = 0; i < numMessages; i++)
      -            {
      -               TextMessage messageA = sessionA.createTextMessage("A:This is text message " + i);
      -               producerA.send(messageA);
      -               System.out.println("Sent message: " + messageA.getText());
      -            }
      -		 
      -        
      - -
    15. We start the connection to consume messages
    16. -
      -              connectionA.start();
      -        
      - -
    17. We consume messages from the session A, one at a time. We reached message no 5 the first server will crash
    18. -
      -            consume(sessionA, queue, numMessages, "A");
      -        
      - -
    19. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
    20. - -
      -           
      -           if (connectionA != null)
      -           {
      -              connectionA.close();
      -           }
      -
      -           if (initialContext != null)
      -           {
      -              initialContext.close();
      -           }
      -		 
      -        
      -
    diff --git a/examples/jms/client-side-load-balancing/pom.xml b/examples/jms/client-side-load-balancing/pom.xml index 77c8186aad..40fed73d81 100644 --- a/examples/jms/client-side-load-balancing/pom.xml +++ b/examples/jms/client-side-load-balancing/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-client-side-load-balancing-example + client-side-load-balancing jar ActiveMQ Artemis JMS Client Side Load Balancing Example @@ -41,155 +42,164 @@ under the License. artemis-jms-client ${project.version} - - org.apache.geronimo.specs - geronimo-jms_2.0_spec - - example - - - - org.apache.activemq - artemis-maven-plugin - - - create0 - - create - - - ${basedir}/target/server0 - true - - - - create1 - - create - - - ${basedir}/target/server1 - true - 1 - - - - create2 - - create - - - ${basedir}/target/server2 - true - 2 - - - - start0 - - cli - - - true - ${basedir}/target/server0 - tcp://localhost:61616 - - run - - server0 - - - - start1 - - cli - - - true - ${basedir}/target/server1 - tcp://localhost:61617 - - run - - server1 - - - - start2 - - cli - - - true - ${basedir}/target/server2 - tcp://localhost:61618 - - run - - server2 - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.ClientSideLoadBalancingExample - - - - stop0 - - cli - - - ${basedir}/target/server0 - - stop - - - - - stop1 - - cli - - - ${basedir}/target/server1 - - stop - - - - - stop2 - - cli - - - ${basedir}/target/server2 - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-client-side-load-balancing-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create0 + + create + + + ${noServer} + ${basedir}/target/server0 + true + + + + create1 + + create + + + ${noServer} + ${basedir}/target/server1 + true + 1 + + + + create2 + + create + + + ${noServer} + ${basedir}/target/server2 + true + 2 + + + + start0 + + cli + + + true + ${noServer} + ${basedir}/target/server0 + tcp://localhost:61616 + + run + + server0 + + + + start1 + + cli + + + ${noServer} + true + ${basedir}/target/server1 + tcp://localhost:61617 + + run + + server1 + + + + start2 + + cli + + + ${noServer} + true + ${basedir}/target/server2 + tcp://localhost:61618 + + run + + server2 + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.ClientSideLoadBalancingExample + + + + stop0 + + cli + + + ${noServer} + ${basedir}/target/server0 + + stop + + + + + stop1 + + cli + + + ${noServer} + ${basedir}/target/server1 + + stop + + + + + stop2 + + cli + + + ${noServer} + ${basedir}/target/server2 + + stop + + + + + + + org.apache.activemq.examples.jms + client-side-load-balancing + ${project.version} + + + + + diff --git a/examples/jms/client-side-load-balancing/readme.html b/examples/jms/client-side-load-balancing/readme.html index 7cfc6843b1..dc0662306f 100644 --- a/examples/jms/client-side-load-balancing/readme.html +++ b/examples/jms/client-side-load-balancing/readme.html @@ -26,6 +26,7 @@ under the License.

    JMS Client-Side Load-Balancing Example

    +
    To run the example, simply type mvn verify from this directory, 
    or mvn -PnoServer verify if you want to start and create the server manually.

    This example demonstrates how connnections created from a single JMS Connection factory can be created to different nodes of the cluster. In other words it demonstrates how ActiveMQ Artemis does client side load balancing of @@ -40,129 +41,9 @@ under the License.

    This example starts three servers which all broadcast their location using UDP discovery. The UDP broadcast configuration can be seen in the broker.xml file.

    A JMS ConnectionFactory is deployed on each server specifying the discovery group that will be used by that - connection factory.

    + connection factory.

    For more information on ActiveMQ Artemis load balancing, and clustering in general, please see the clustering - section of the user manual.

    + section of the user manual.

    -

    Example step-by-step

    -

    To run the example, simply type mvn verify -Pexample from this directory

    - -
      -
    1. Get an initial context for looking up JNDI from server 0.
    2. -
      -           initialContext = getContext(0);
      -        
      - -
    3. Look-up the JMS Queue object from JNDI
    4. -
      -           Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue");
      -        
      - -
    5. Look-up a JMS Connection Factory object from JNDI on server 0
    6. -
      -           ConnectionFactory connectionFactory = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
      -        
      - -
    7. We create 3 JMS connections from the same connection factory. Since we are using round-robin - load-balancing this should result in each sessions being connected to a different node of the cluster
    8. -
      -           
      -        Connection conn = connectionFactory.createConnection();
      -        connectionA = connectionFactory.createConnection();
      -        connectionB = connectionFactory.createConnection();
      -        connectionC = connectionFactory.createConnection();
      -        conn.close();
      -           
      -        
      - -
    9. We create JMS Sessions
    10. -
      -           
      -         Session sessionA = connectionA.createSession(false, Session.AUTO_ACKNOWLEDGE);
      -         Session sessionB = connectionB.createSession(false, Session.AUTO_ACKNOWLEDGE);
      -         Session sessionC = connectionC.createSession(false, Session.AUTO_ACKNOWLEDGE);
      -           
      -        
      - -
    11. We create JMS MessageProducer objects on the sessions
    12. -
      -           
      -        MessageProducer producerA = sessionA.createProducer(queue);
      -        MessageProducer producerB = sessionB.createProducer(queue);
      -        MessageProducer producerC = sessionC.createProducer(queue);
      -           
      -        
      - -
    13. We send some messages on each producer
    14. -
      -           
      -         final int numMessages = 10;
      -
      -         for (int i = 0; i < numMessages; i++)
      -         {
      -            TextMessage messageA = sessionA.createTextMessage("A:This is text message " + i);
      -            producerA.send(messageA);
      -            System.out.println("Sent message: " + messageA.getText());
      -            
      -            TextMessage messageB = sessionB.createTextMessage("B:This is text message " + i);
      -            producerB.send(messageB);
      -            System.out.println("Sent message: " + messageB.getText());
      -            
      -            TextMessage messageC = sessionC.createTextMessage("C:This is text message " + i);
      -            producerC.send(messageC);
      -            System.out.println("Sent message: " + messageC.getText());            
      -         }
      -            
      -        
      - -
    15. We start the connection to consume messages
    16. -
      -           
      -       connectionA.start();
      -       connectionB.start();
      -       connectionC.start();
      -           
      -        
      - -
    17. We consume messages from the 3 session, one at a time.
      - We try to consume one more message than expected from each session. If - the session were not properly load-balanced, we would be missing a - message from one of the sessions at the end.
    18. -
      -            
      -         consume(sessionA, queue, numMessages, "A");
      -         consume(sessionB, queue, numMessages, "B");
      -         consume(sessionC, queue, numMessages, "C");
      -            
      -         
      - -
    19. And finally (no pun intended), always remember to close your JMS resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
    20. - -
      -           
      -	finally
      -	{
      -	     if (connectionA != null)
      -         {
      -            connectionA.close();
      -         }
      -         if (connectionB != null)
      -         {
      -            connectionB.close();
      -         }
      -         if (connectionC != null)
      -         {
      -            connectionC.close();
      -         }
      -
      -         if (initialContext != null)
      -         {
      -            initialContext.close();
      -         }
      -	}
      -           
      -        
      - -
    - + diff --git a/examples/jms/clustered-durable-subscription/pom.xml b/examples/jms/clustered-durable-subscription/pom.xml index 041fbe30fa..5b678d2302 100644 --- a/examples/jms/clustered-durable-subscription/pom.xml +++ b/examples/jms/clustered-durable-subscription/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-clustered-durable-subscription-example + clustered-durable-subscription jar ActiveMQ Artemis JMS Clustered Durable Subscription Example @@ -37,116 +38,130 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create0 - - create - - - ${basedir}/target/server0 - ${basedir}/target/classes/activemq/server0 - - - - create1 - - create - - - ${basedir}/target/server1 - ${basedir}/target/classes/activemq/server1 - 1 - - - - start0 - - cli - - - true - ${basedir}/target/server0 - tcp://localhost:61616 - - run - - server0 - - - - start1 - - cli - - - true - ${basedir}/target/server1 - tcp://localhost:61617 - - run - - server1 - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.ClusteredDurableSubscriptionExample - - - - stop0 - - cli - - - ${basedir}/target/server0 - - stop - - - - - stop1 - - cli - - - ${basedir}/target/server1 - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-clustered-durable-subscription-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create0 + + create + + + ${noServer} + true + ${basedir}/target/server0 + ${basedir}/target/classes/activemq/server0 + + + + create1 + + create + + + ${noServer} + true + ${basedir}/target/server1 + ${basedir}/target/classes/activemq/server1 + 1 + + + + start0 + + cli + + + ${noServer} + true + ${basedir}/target/server0 + tcp://localhost:61616 + + run + + server0 + + + + start1 + + cli + + + ${noServer} + true + ${basedir}/target/server1 + tcp://localhost:61617 + + run + + server1 + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.ClusteredDurableSubscriptionExample + + + + + stop0 + + cli + + + ${noServer} + ${basedir}/target/server0 + + stop + + + + + stop1 + + cli + + + ${noServer} + ${basedir}/target/server1 + + stop + + + + + + + org.apache.activemq.examples.jms + clustered-durable-subscription + ${project.version} + + + + + diff --git a/examples/jms/clustered-durable-subscription/readme.html b/examples/jms/clustered-durable-subscription/readme.html index 0d172142ac..57597bdd98 100644 --- a/examples/jms/clustered-durable-subscription/readme.html +++ b/examples/jms/clustered-durable-subscription/readme.html @@ -27,6 +27,8 @@ under the License.

    JMS Durable Subscription Example

    +
    To run the example, simply type mvn verify from this directory, 
    or mvn -PnoServer verify if you want to start and create the server manually.
    +

    This example demonstrates a clustered JMS durable subscription. Normally durable subscriptions exist on a single node and can only have one subscriber at any one time, however, with ActiveMQ Artemis it's possible to create durable subscription instances with the same name and client-id @@ -45,6 +47,7 @@ under the License. JNDI, these could be instantiated directly.

    Here's the relevant snippet from the server configuration, which tells the server to form a cluster between the two nodes and to load balance the messages between the nodes.

    +

    The cli create method will define this section by default if you use --clustered as a parameter

          <cluster-connection name="my-cluster">
             <address>jms</address>
    @@ -59,155 +62,5 @@ under the License.
          

    For more information on ActiveMQ Artemis load balancing, and clustering in general, please see the clustering section of the user manual.

    -

    Example step-by-step

    -

    To run the example, simply type mvn verify -Pexample from this directory

    - -
      -
    1. Get an initial context for looking up JNDI from server 0.
    2. -
      -           
      -   ic0 = getContext(0);
      -   
      -        
      - -
    3. Look-up the JMS Topic object from JNDI
    4. -
      -           Topic topic = (Topic)ic0.lookup("/topic/exampleTopic");
      -        
      - -
    5. Look-up a JMS Connection Factory object from JNDI on server 0
    6. -
      -           ConnectionFactory cf0 = (ConnectionFactory)ic0.lookup("/ConnectionFactory");
      -        
      - -
    7. Get an initial context for looking up JNDI from server 1.
    8. -
      -           ic1 = getContext(1);
      -        
      - -
    9. Look-up a JMS Connection Factory object from JNDI on server 1
    10. -
      -           ConnectionFactory cf1 = (ConnectionFactory)ic1.lookup("/ConnectionFactory");
      -           
      -        
      - -
    11. We create a JMS Connection connection0 which is a connection to server 0 - and set the same client-id.
    12. -
      -          
      -   connection0 = cf0.createConnection();
      -   final String clientID = "my-client-id";
      -   connection0.setClientID(clientID);
      -          
      -        
      - -
    13. We create a JMS Connection connection1 which is a connection to server 1 - and set the same client-id.
    14. -
      -          
      -   connection1 = cf1.createConnection();
      -   connection1.setClientID(clientID);
      -          
      -        
      - -
    15. We create a JMS Session on server 0
    16. -
      -           
      -   Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE);
      -           
      -        
      - -
    17. We create a JMS Session on server 1
    18. -
      -           
      -   Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
      -            
      -        
      - -
    19. We start the connections to ensure delivery occurs on them
    20. -
      -           
      -   connection0.start();
      -
      -   connection1.start();
      -           
      -        
      - -
    21. We create JMS durable subscriptions with the same name and client-id on both nodes - of the cluster -
    22. -
      -           
      -   final String subscriptionName = "my-subscription";
      -
      -   MessageConsumer subscriber0 = session0.createDurableSubscriber(topic, subscriptionName);
      -
      -   MessageConsumer subscriber1 = session1.createDurableSubscriber(topic, subscriptionName);
      -           
      -        
      - -
    23. We create a JMS MessageProducer object on server 0.
    24. -
      -           
      -   MessageProducer producer = session0.createProducer(topic);
      -        
      - -
    25. We send some messages to server 0.
    26. -
      -           
      -	final int numMessages = 10;
      -
      -	for (int i = 0; i < numMessages; i++)
      -	{
      -	   TextMessage message = session0.createTextMessage("This is text message " + i);
      -
      -	   producer.send(message);
      -
      -	   System.out.println("Sent message: " + message.getText());
      -	}
      -           
      -        
      - -
    27. - We now consume those messages on *both* server 0 and server 1. - Note that the messages have been load-balanced between the two nodes, with some - messages on node 0 and others on node 1. - The "logical" subscription is distributed across the cluster and contains exactly one copy of all the messages sent. -
    28. -
      -           
      -	for (int i = 0; i < numMessages; i += 2)
      -	{
      -	   TextMessage message0 = (TextMessage)consumer0.receive(5000);
      -
      -	   System.out.println("Got message: " + message0.getText() + " from node 0");
      -
      -	   TextMessage message1 = (TextMessage)consumer1.receive(5000);
      -
      -	   System.out.println("Got message: " + message1.getText() + " from node 1");
      -	}
      -           
      -        
      - -
    29. And finally (no pun intended), always remember to close your JMS resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
    30. - -
      -           
      -	finally
      -	{
      -	   if (connection0 != null)
      -	   {
      -	      connection0.close();
      -	   }
      -
      -	   if (connection1 != null)
      -	   {
      -	      connection1.close();
      -	   }
      -	}
      -           
      -        
      - -
    - + diff --git a/examples/jms/clustered-durable-subscription/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredDurableSubscriptionExample.java b/examples/jms/clustered-durable-subscription/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredDurableSubscriptionExample.java index 31d1434419..2dceb7c5fb 100644 --- a/examples/jms/clustered-durable-subscription/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredDurableSubscriptionExample.java +++ b/examples/jms/clustered-durable-subscription/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredDurableSubscriptionExample.java @@ -26,6 +26,8 @@ import javax.jms.Topic; import javax.naming.InitialContext; import java.util.Hashtable; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; + /** * A simple example that shows a JMS Durable Subscription across two nodes of a cluster. * @@ -40,36 +42,15 @@ public class ClusteredDurableSubscriptionExample Connection connection1 = null; - InitialContext ic0 = null; - - InitialContext ic1 = null; - try { - // Step 1. Get an initial context for looking up JNDI from server 0 - Hashtable properties = new Hashtable(); - properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); - properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61616"); - properties.put("topic.topic/exampleTopic", "exampleTopic"); - ic0 = new InitialContext(properties); + // Step 1. Instantiate the connection factory on server 0 + ConnectionFactory cf0 = new ActiveMQConnectionFactory("tcp://localhost:61616"); - // Step 2. Look-up the JMS Topic object from JNDI - Topic topic = (Topic)ic0.lookup("topic/exampleTopic"); + // Step 2. nstantiate the connection factory on server 1 + ConnectionFactory cf1 = new ActiveMQConnectionFactory("tcp://localhost:61617"); - // Step 3. Look-up a JMS Connection Factory object from JNDI on server 0 - ConnectionFactory cf0 = (ConnectionFactory)ic0.lookup("ConnectionFactory"); - - // Step 4. Get an initial context for looking up JNDI from server 1 - - properties = new Hashtable(); - properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); - 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 - ConnectionFactory cf1 = (ConnectionFactory)ic1.lookup("ConnectionFactory"); - - // Step 6. We create a JMS Connection connection0 which is a connection to server 0 + // Step 3. We create a JMS Connection connection0 which is a connection to server 0 // and set the client-id connection0 = cf0.createConnection(); @@ -77,38 +58,41 @@ public class ClusteredDurableSubscriptionExample connection0.setClientID(clientID); - // Step 7. We create a JMS Connection connection1 which is a connection to server 1 + // Step 4. We create a JMS Connection connection1 which is a connection to server 1 // and set the same client-id connection1 = cf1.createConnection(); connection1.setClientID(clientID); - // Step 8. We create a JMS Session on server 0 + // Step 5. We create a JMS Session on server 0 Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE); - // Step 9. We create a JMS Session on server 1 + // Step 6. We create a JMS Session on server 1 Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE); - // Step 10. We start the connections to ensure delivery occurs on them + // Step 7. We start the connections to ensure delivery occurs on them connection0.start(); connection1.start(); - // Step 11. We create JMS durable subscriptions with the same name and client-id on both nodes + // Step 8. We create JMS durable subscriptions with the same name and client-id on both nodes // of the cluster final String subscriptionName = "my-subscription"; + // Step 9. lookup the topic + Topic topic = session0.createTopic("exampleTopic"); + MessageConsumer subscriber0 = session0.createDurableSubscriber(topic, subscriptionName); MessageConsumer subscriber1 = session1.createDurableSubscriber(topic, subscriptionName); Thread.sleep(1000); - // Step 12. We create a JMS MessageProducer object on server 0 + // Step 10. We create a JMS MessageProducer object on server 0 MessageProducer producer = session0.createProducer(topic); - // Step 13. We send some messages to server 0 + // Step 11. We send some messages to server 0 final int numMessages = 10; @@ -121,7 +105,7 @@ public class ClusteredDurableSubscriptionExample System.out.println("Sent message: " + message.getText()); } - // Step 14. We now consume those messages on *both* server 0 and server 1. + // Step 12. We now consume those messages on *both* server 0 and server 1. // Note that the messages have been load-balanced between the two nodes, with some // messages on node 0 and others on node 1. // The "logical" subscription is distributed across the cluster and contains exactly one copy of all the @@ -150,16 +134,6 @@ public class ClusteredDurableSubscriptionExample { connection1.close(); } - - if (ic0 != null) - { - ic0.close(); - } - - if (ic1 != null) - { - ic1.close(); - } } } } diff --git a/examples/jms/clustered-durable-subscription/src/main/resources/activemq/server0/broker.xml b/examples/jms/clustered-durable-subscription/src/main/resources/activemq/server0/broker.xml index 6214a63a6c..2bfaeaefdd 100644 --- a/examples/jms/clustered-durable-subscription/src/main/resources/activemq/server0/broker.xml +++ b/examples/jms/clustered-durable-subscription/src/main/resources/activemq/server0/broker.xml @@ -29,13 +29,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/clustered-durable-subscription/src/main/resources/activemq/server1/broker.xml b/examples/jms/clustered-durable-subscription/src/main/resources/activemq/server1/broker.xml index 3d1cb2ea76..8134f2727f 100644 --- a/examples/jms/clustered-durable-subscription/src/main/resources/activemq/server1/broker.xml +++ b/examples/jms/clustered-durable-subscription/src/main/resources/activemq/server1/broker.xml @@ -29,13 +29,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/clustered-grouping/pom.xml b/examples/jms/clustered-grouping/pom.xml index 0f9f1015eb..86338f3e68 100644 --- a/examples/jms/clustered-grouping/pom.xml +++ b/examples/jms/clustered-grouping/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-clustered-grouping-example + clustered-grouping jar ActiveMQ Artemis JMS CLustered Grouping Example @@ -37,152 +38,166 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create0 - - create - - - ${basedir}/target/server0 - ${basedir}/target/classes/activemq/server0 - - - - create1 - - create - - - ${basedir}/target/server1 - ${basedir}/target/classes/activemq/server1 - - - - create2 - - create - - - ${basedir}/target/server2 - ${basedir}/target/classes/activemq/server2 - - - - start0 - - cli - - - true - ${basedir}/target/server0 - tcp://localhost:61616 - - run - - server0 - - - - start1 - - cli - - - true - ${basedir}/target/server1 - tcp://localhost:61617 - - run - - server1 - - - - start2 - - cli - - - true - ${basedir}/target/server2 - tcp://localhost:61618 - - run - - server2 - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.ClusteredGroupingExample - - - - stop0 - - cli - - - ${basedir}/target/server0 - - stop - - - - - stop1 - - cli - - - ${basedir}/target/server1 - - stop - - - - - stop2 - - cli - - - ${basedir}/target/server2 - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-clustered-grouping-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create0 + + create + + + ${noServer} + ${basedir}/target/server0 + ${basedir}/target/classes/activemq/server0 + + + + create1 + + create + + + ${noServer} + ${basedir}/target/server1 + ${basedir}/target/classes/activemq/server1 + + + + create2 + + create + + + ${noServer} + ${basedir}/target/server2 + ${basedir}/target/classes/activemq/server2 + + + + start0 + + cli + + + ${noServer} + true + ${basedir}/target/server0 + tcp://localhost:61616 + + run + + server0 + + + + start1 + + cli + + + ${noServer} + true + ${basedir}/target/server1 + tcp://localhost:61617 + + run + + server1 + + + + start2 + + cli + + + ${noServer} + true + ${basedir}/target/server2 + tcp://localhost:61618 + + run + + server2 + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.ClusteredGroupingExample + + + + stop0 + + cli + + + ${noServer} + ${basedir}/target/server0 + + stop + + + + + stop1 + + cli + + + ${noServer} + ${basedir}/target/server1 + + stop + + + + + stop2 + + cli + + + ${noServer} + ${basedir}/target/server2 + + stop + + + + + + + org.apache.activemq.examples.jms + clustered-grouping + ${project.version} + + + + + diff --git a/examples/jms/clustered-grouping/readme.html b/examples/jms/clustered-grouping/readme.html index 1f5010cf13..c605168047 100644 --- a/examples/jms/clustered-grouping/readme.html +++ b/examples/jms/clustered-grouping/readme.html @@ -25,6 +25,8 @@ under the License.

    JMS Clustered Grouping Example

    +
    To run the example, simply type mvn verify from this directory, 
    or mvn -PnoServer verify if you want to start and create the server manually.
    +

    This example demonstrates how to ensure strict ordering across a cluster using clustered message grouping

    We create 3 nodes each with a grouping message handler, one with a Local handler and 2 with a Remote handler.

    The local handler acts as an arbitrator for the 2 remote handlers, holding the information on routes and communicating @@ -75,191 +77,5 @@ under the License.

    -

    For more information on ActiveMQ Artemis clustering and grouping see the clustering and grouping - section of the user manual.

    -

    Example step-by-step

    -

    To run the example, simply type mvn verify -Pexample from this directory

    - -
      -
    1. Get an initial context for looking up JNDI from server 0.
    2. -
      -           ic0 = getContext(0);
      -        
      - -
    3. Look-up the JMS Queue object from JNDI
    4. -
      -           Queue queue = (Queue)ic0.lookup("/queue/exampleQueue");
      -        
      - -
    5. Look-up a JMS Connection Factory object from JNDI on server 0
    6. -
      -           ConnectionFactory cf0 = (ConnectionFactory)ic0.lookup("/ConnectionFactory");
      -        
      - -
    7. Get an initial context for looking up JNDI from server 1.
    8. -
      -           ic1 = getContext(1);
      -        
      - -
    9. Look-up a JMS Connection Factory object from JNDI on server 1
    10. -
      -           ConnectionFactory cf1 = (ConnectionFactory)ic1.lookup("/ConnectionFactory");
      -           
      -        
      - -
    11. Get an initial context for looking up JNDI from server 2.
    12. -
      -           ic2 = getContext(2);
      -        
      - -
    13. Look-up a JMS Connection Factory object from JNDI on server 2
    14. -
      -           ConnectionFactory cf2 = (ConnectionFactory)ic2.lookup("/ConnectionFactory");
      -           
      -        
      - -
    15. We create a JMS Connection connection0 which is a connection to server 0
    16. -
      -           connection0 = cf0.createConnection();
      -        
      - -
    17. We create a JMS Connection connection0 which is a connection to server 1
    18. -
      -           connection1 = cf1.createConnection();
      -        
      - -
    19. We create a JMS Connection connection0 which is a connection to server 2
    20. -
      -           connection2 = cf2.createConnection();
      -        
      - -
    21. We create a JMS Session on server 0
    22. -
      -           Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE);
      -        
      - -
    23. We create a JMS Session on server 1
    24. -
      -           Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
      -        
      - -
    25. We create a JMS Session on server 2
    26. -
      -           Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
      -        
      - -
    27. We start the connections to ensure delivery occurs on them
    28. -
      -           
      -         connection0.start();
      -
      -         connection1.start();
      -
      -         connection2.start();
      -        
      - -
    29. We create JMS MessageConsumer objects on server 0
    30. -
      -           MessageConsumer consumer = session0.createConsumer(queue);
      -        
      - -
    31. We create a JMS MessageProducer object on server 0, 1 and 2
    32. -
      -           
      -         MessageProducer producer0 = session0.createProducer(queue);
      -
      -         MessageProducer producer1 = session1.createProducer(queue);
      -
      -         MessageProducer producer2 = session2.createProducer(queue);
      -        
      - -
    33. We send some messages to server 0, 1 and 2 with the same groupid set
    34. -
      -           
      -         final int numMessages = 10;
      -
      -         for (int i = 0; i < numMessages; i++)
      -         {
      -            TextMessage message = session0.createTextMessage("This is text message " + i);
      -
      -            message.setStringProperty(ActiveMQMessage.JMSXGROUPID, "Group-0");
      -
      -            producer0.send(message);
      -
      -            System.out.println("Sent messages: " + message.getText() + " to node 0");
      -         }
      -
      -         for (int i = 0; i < numMessages; i++)
      -         {
      -            TextMessage message = session1.createTextMessage("This is text message " + (i + 10));
      -
      -            message.setStringProperty(ActiveMQMessage.JMSXGROUPID, "Group-0");
      -
      -            producer1.send(message);
      -
      -            System.out.println("Sent messages: " + message.getText() + " to node 1");
      -
      -         }
      -
      -         for (int i = 0; i < numMessages; i++)
      -         {
      -            TextMessage message = session2.createTextMessage("This is text message " + (i + 20));
      -
      -            message.setStringProperty(ActiveMQMessage.JMSXGROUPID, "Group-0");
      -
      -            producer2.send(message);
      -
      -            System.out.println("Sent messages: " + message.getText() + " to node 2");
      -         }
      -        
      -        
      - -
    35. We now consume those messages from server 0. We note the messages have all been sent to the same consumer on the same node
    36. -
      -           
      -         for (int i = 0; i < numMessages * 3; i++)
      -         {
      -            TextMessage message0 = (TextMessage)consumer.receive(5000);
      -
      -            System.out.println("Got message: " + message0.getText() + " from node 0");
      -
      -         }
      -        
      -        
      -
    37. Finally, Be sure to close our resources!
    38. -
      -           
      -         if (connection0 != null)
      -         {
      -            connection0.close();
      -         }
      -
      -         if (connection1 != null)
      -         {
      -            connection1.close();
      -         }
      -
      -         if (connection2 != null)
      -         {
      -            connection2.close();
      -         }
      -
      -         if (ic0 != null)
      -         {
      -            ic0.close();
      -         }
      -
      -         if (ic1 != null)
      -         {
      -            ic1.close();
      -         }
      -
      -         if (ic2 != null)
      -         {
      -            ic2.close();
      -         }
      -        
      - -
    - + diff --git a/examples/jms/clustered-grouping/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredGroupingExample.java b/examples/jms/clustered-grouping/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredGroupingExample.java index a60ea6b656..04fec83a47 100644 --- a/examples/jms/clustered-grouping/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredGroupingExample.java +++ b/examples/jms/clustered-grouping/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredGroupingExample.java @@ -23,8 +23,10 @@ import javax.jms.MessageProducer; import javax.jms.Queue; import javax.jms.Session; import javax.jms.TextMessage; -import javax.naming.InitialContext; -import java.util.Hashtable; + +import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; +import org.apache.activemq.artemis.jms.client.ActiveMQQueue; /** * A simple example that demonstrates server side load-balancing of messages between the queue instances on different @@ -40,82 +42,58 @@ public class ClusteredGroupingExample Connection connection2 = null; - InitialContext ic0 = null; - - InitialContext ic1 = null; - - InitialContext ic2 = null; - try { - // Step 1. Get an initial context for looking up JNDI from server 0 - Hashtable properties = new Hashtable(); - properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); - properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61616"); - properties.put("queue.queue/exampleQueue", "exampleQueue"); - ic0 = new InitialContext(properties); + // Step 1. We will instantiate the queue object directly on this example + // This could be done through JNDI or JMSession.createQueue + Queue queue = ActiveMQJMSClient.createQueue("exampleQueue"); - // Step 2. Look-up the JMS Queue object from JNDI - Queue queue = (Queue)ic0.lookup("queue/exampleQueue"); + // Step 2. create a connection factory towards server 0. + ConnectionFactory cf0 = new ActiveMQConnectionFactory("tcp://localhost:61616"); - // Step 3. Look-up a JMS Connection Factory object from JNDI on server 0 - ConnectionFactory cf0 = (ConnectionFactory)ic0.lookup("ConnectionFactory"); + // Step 3. create a connection factory towards server 1. + ConnectionFactory cf1 = new ActiveMQConnectionFactory("tcp://localhost:61617"); - // Step 4. Get an initial context for looking up JNDI from server 1 - properties = new Hashtable(); - properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); - properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61617"); - ic1 = new InitialContext(properties); + // Step 4. create a connection factory towards server 2. + ConnectionFactory cf2 = new ActiveMQConnectionFactory("tcp://localhost:61618"); - // Step 5. Look-up a JMS Connection Factory object from JNDI on server 1 - ConnectionFactory cf1 = (ConnectionFactory)ic1.lookup("ConnectionFactory"); - - // Step 4. Get an initial context for looking up JNDI from server 2 - properties = new Hashtable(); - properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); - properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61618"); - ic2 = new InitialContext(properties); - - // Step 5. Look-up a JMS Connection Factory object from JNDI on server 2 - ConnectionFactory cf2 = (ConnectionFactory)ic2.lookup("ConnectionFactory"); - - // Step 6. We create a JMS Connection connection0 which is a connection to server 0 + // Step 5. We create a JMS Connection connection0 which is a connection to server 0 connection0 = cf0.createConnection(); - // Step 7. We create a JMS Connection connection1 which is a connection to server 1 + // Step 6. We create a JMS Connection connection1 which is a connection to server 1 connection1 = cf1.createConnection(); - // Step 8. We create a JMS Connection connection2 which is a connection to server 2 + // Step 7. We create a JMS Connection connection2 which is a connection to server 2 connection2 = cf2.createConnection(); - // Step 9. We create a JMS Session on server 0 + // Step 8. We create a JMS Session on server 0 Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE); - // Step 10. We create a JMS Session on server 1 + // Step 9. We create a JMS Session on server 1 Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE); - // Step 11. We create a JMS Session on server 2 + // Step 10. We create a JMS Session on server 2 Session session2 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE); - // Step 12. We start the connections to ensure delivery occurs on them + // Step 11. We start the connections to ensure delivery occurs on them connection0.start(); connection1.start(); connection2.start(); - // Step 13. We create JMS MessageConsumer objects on server 0 + // Step 12. We create JMS MessageConsumer objects on server 0 MessageConsumer consumer = session0.createConsumer(queue); - // Step 14. We create a JMS MessageProducer object on server 0, 1 and 2 + // Step 13. We create a JMS MessageProducer object on server 0, 1 and 2 MessageProducer producer0 = session0.createProducer(queue); MessageProducer producer1 = session1.createProducer(queue); MessageProducer producer2 = session2.createProducer(queue); - // Step 15. We send some messages to server 0, 1 and 2 with the same groupid set + // Step 14. We send some messages to server 0, 1 and 2 with the same groupid set final int numMessages = 10; @@ -153,7 +131,7 @@ public class ClusteredGroupingExample System.out.println("Sent messages: " + message.getText() + " to node 2"); } - // Step 16. We now consume those messages from server 0 + // Step 15. We now consume those messages from server 0 // We note the messages have all been sent to the same consumer on the same node for (int i = 0; i < numMessages * 3; i++) @@ -182,21 +160,6 @@ public class ClusteredGroupingExample { connection2.close(); } - - if (ic0 != null) - { - ic0.close(); - } - - if (ic1 != null) - { - ic1.close(); - } - - if (ic2 != null) - { - ic2.close(); - } } } } diff --git a/examples/jms/clustered-grouping/src/main/resources/activemq/server0/broker.xml b/examples/jms/clustered-grouping/src/main/resources/activemq/server0/broker.xml index 77fa2e6454..45200591ed 100644 --- a/examples/jms/clustered-grouping/src/main/resources/activemq/server0/broker.xml +++ b/examples/jms/clustered-grouping/src/main/resources/activemq/server0/broker.xml @@ -29,13 +29,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/clustered-grouping/src/main/resources/activemq/server1/broker.xml b/examples/jms/clustered-grouping/src/main/resources/activemq/server1/broker.xml index fabd98d8ce..4765f7a2ea 100644 --- a/examples/jms/clustered-grouping/src/main/resources/activemq/server1/broker.xml +++ b/examples/jms/clustered-grouping/src/main/resources/activemq/server1/broker.xml @@ -29,13 +29,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/clustered-grouping/src/main/resources/activemq/server2/broker.xml b/examples/jms/clustered-grouping/src/main/resources/activemq/server2/broker.xml index 07d18fcd0a..16bf2eb7bd 100644 --- a/examples/jms/clustered-grouping/src/main/resources/activemq/server2/broker.xml +++ b/examples/jms/clustered-grouping/src/main/resources/activemq/server2/broker.xml @@ -29,13 +29,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/clustered-jgroups/pom.xml b/examples/jms/clustered-jgroups/pom.xml index fc90be7024..9930edcb98 100644 --- a/examples/jms/clustered-jgroups/pom.xml +++ b/examples/jms/clustered-jgroups/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -37,123 +38,133 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - - org.jgroups:jgroups:3.6.0.Final - - ${basedir}/target/server0 - ${basedir}/target/classes/activemq/server0 - - - - create1 - - create - - - - - org.jgroups:jgroups:3.6.0.Final - - ${basedir}/target/server1 - ${basedir}/target/classes/activemq/server1 - - - - start0 - - cli - - - true - ${basedir}/target/server0 - tcp://localhost:61616 - - run - - server0 - - - - start1 - - cli - - - true - ${basedir}/target/server1 - tcp://localhost:61617 - - run - - server1 - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.ClusteredJgroupsExample - - - - stop0 - - cli - - - ${basedir}/target/server0 - - stop - - - - - stop1 - - cli - - - ${basedir}/target/server1 - - stop - - - - - - - org.apache.activemq.examples.jms - clustered-jgroups - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + + + org.jgroups:jgroups:3.6.0.Final + + ${noServer} + ${basedir}/target/server0 + ${basedir}/target/classes/activemq/server0 + + + + create1 + + create + + + + + org.jgroups:jgroups:3.6.0.Final + + ${noServer} + ${basedir}/target/server1 + ${basedir}/target/classes/activemq/server1 + + + + start0 + + cli + + + ${noServer} + true + ${basedir}/target/server0 + tcp://localhost:61616 + + run + + server0 + + + + start1 + + cli + + + ${noServer} + true + ${basedir}/target/server1 + tcp://localhost:61617 + + run + + server1 + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.ClusteredJgroupsExample + + + + stop0 + + cli + + + ${noServer} + ${basedir}/target/server0 + + stop + + + + + stop1 + + cli + + + ${basedir}/target/server1 + + stop + + + + + + + org.apache.activemq.examples.jms + clustered-jgroups + ${project.version} + + + + + diff --git a/examples/jms/clustered-jgroups/readme.html b/examples/jms/clustered-jgroups/readme.html index a88ce0d9ab..123e33ac6c 100644 --- a/examples/jms/clustered-jgroups/readme.html +++ b/examples/jms/clustered-jgroups/readme.html @@ -27,7 +27,9 @@ under the License.

    ActiveMQ Artemis Clustering with JGroups Example

    -

    This example demonstrates the working of a two node cluster using JGroups as the underlying topology broadcasting/discovery +

    To run the example, simply type mvn verify from this directory, 
    or mvn -PnoServer verify if you want to start and create the server manually.
    + +

    This example demonstrates the working of a two node cluster using JGroups as the underlying topology broadcasting/discovery technique.

    We deploy a queue on to the cluster, then create a consumer on the queue on each node, and we create a producer on only one of the nodes.

    We then send some messages via the producer, and we verify that both consumers receive the sent messages @@ -58,150 +60,8 @@ under the License. </discovery-group> </discovery-groups> - +

    For more information on ActiveMQ Artemis clustering in general, please see the clustering - section of the user manual.

    -

    Example step-by-step

    -

    To run the example, simply type ./build.sh (or build.bat on windows) from this directory

    - -
      -
    1. Get an initial context for looking up JNDI from server 0.
    2. -
      -           
      -   ic0 = getContext(0);
      -   
      -        
      - -
    3. Look-up the JMS Queue object from JNDI
    4. -
      -           Queue queue = (Queue)ic0.lookup("/queue/exampleQueue");
      -        
      - -
    5. Look-up a JMS Connection Factory object from JNDI on server 0
    6. -
      -           ConnectionFactory cf0 = (ConnectionFactory)ic0.lookup("/ConnectionFactory");
      -        
      - -
    7. Get an initial context for looking up JNDI from server 1.
    8. -
      -           ic1 = getContext(1);
      -        
      - -
    9. Look-up a JMS Connection Factory object from JNDI on server 1
    10. -
      -           ConnectionFactory cf1 = (ConnectionFactory)ic1.lookup("/ConnectionFactory");
      -           
      -        
      - -
    11. We create a JMS Connection connection0 which is a connection to server 0
    12. -
      -          
      -   connection0 = cf0.createConnection();
      -          
      -        
      - -
    13. We create a JMS Connection connection1 which is a connection to server 1
    14. -
      -          
      -   connection1 = cf1.createConnection();
      -          
      -        
      - -
    15. We create a JMS Session on server 0
    16. -
      -           
      -   Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE);
      -           
      -        
      - -
    17. We create a JMS Session on server 1
    18. -
      -           
      -   Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
      -            
      -        
      - -
    19. We start the connections to ensure delivery occurs on them
    20. -
      -           
      -   connection0.start();
      -
      -   connection1.start();
      -           
      -        
      - -
    21. We create JMS MessageConsumer objects on server 0 and server 1
    22. -
      -           
      -   MessageConsumer consumer0 = session0.createConsumer(queue);
      -
      -   MessageConsumer consumer1 = session1.createConsumer(queue);
      -           
      -        
      - -
    23. We create a JMS MessageProducer object on server 0.
    24. -
      -           
      -   MessageProducer producer = session0.createProducer(queue);
      -        
      - -
    25. We send some messages to server 0.
    26. -
      -           
      -	final int numMessages = 10;
      -
      -	for (int i = 0; i < numMessages; i++)
      -	{
      -	   TextMessage message = session0.createTextMessage("This is text message " + i);
      -	      
      -	   producer.send(message);
      -	
      -	   System.out.println("Sent message: " + message.getText());
      -	}
      -           
      -        
      - -
    27. We now consume those messages on *both* server 0 and server 1. - We note the messages have been distributed between servers in a round robin fashion. - ActiveMQ Artemis has load balanced the messages between the available consumers on the different nodes. - ActiveMQ Artemis can be configured to always load balance messages to all nodes, or to only balance messages - to nodes which have consumers with no or matching selectors. See the user manual for more details.
    28. - JMS Queues implement point-to-point message where each message is only ever consumed by a - maximum of one consumer. -
      -           
      -	for (int i = 0; i < numMessages; i += 2)
      -	{
      -	   TextMessage message0 = (TextMessage)consumer0.receive(5000);
      -	
      -	   System.out.println("Got message: " + message0.getText() + " from node 0");
      -	
      -	   TextMessage message1 = (TextMessage)consumer1.receive(5000);
      -	
      -	   System.out.println("Got message: " + message1.getText() + " from node 1");
      -	}
      -           
      -        
      - -
    29. And finally (no pun intended), always remember to close your JMS resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
    30. - -
      -           
      -	finally
      -	{
      -	   if (connection0 != null)
      -	   {
      -	      connection0.close();
      -	   }
      -	      
      -	   if (connection1 != null)
      -	   {
      -	      connection1.close();
      -	   }
      -	}
      -           
      -        
      - -
    + section of the user manual.

    diff --git a/examples/jms/clustered-jgroups/src/main/resources/activemq/server0/broker.xml b/examples/jms/clustered-jgroups/src/main/resources/activemq/server0/broker.xml index 4af9867449..17809e541d 100644 --- a/examples/jms/clustered-jgroups/src/main/resources/activemq/server0/broker.xml +++ b/examples/jms/clustered-jgroups/src/main/resources/activemq/server0/broker.xml @@ -29,13 +29,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/clustered-jgroups/src/main/resources/activemq/server1/broker.xml b/examples/jms/clustered-jgroups/src/main/resources/activemq/server1/broker.xml index 3393a42fd4..267eae78cd 100644 --- a/examples/jms/clustered-jgroups/src/main/resources/activemq/server1/broker.xml +++ b/examples/jms/clustered-jgroups/src/main/resources/activemq/server1/broker.xml @@ -29,13 +29,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/clustered-queue/pom.xml b/examples/jms/clustered-queue/pom.xml index 7b4287542e..6bd15371d5 100644 --- a/examples/jms/clustered-queue/pom.xml +++ b/examples/jms/clustered-queue/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -37,115 +38,126 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create0 - - create - - - ${basedir}/target/server0 - ${basedir}/target/classes/activemq/server0 - - - - create1 - - create - - - ${basedir}/target/server1 - ${basedir}/target/classes/activemq/server1 - - - - start0 - - cli - - - true - ${basedir}/target/server0 - tcp://localhost:61616 - - run - - server0 - - - - start1 - - cli - - - true - ${basedir}/target/server1 - tcp://localhost:61617 - - run - - server1 - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.ClusteredQueueExample - - - - stop0 - - cli - - - ${basedir}/target/server0 - - stop - - - - - stop1 - - cli - - - ${basedir}/target/server1 - - stop - - - - - - - org.apache.activemq.examples.jms - clustered-queue - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create0 + + create + + + ${noServer} + ${basedir}/target/server0 + ${basedir}/target/classes/activemq/server0 + + + + create1 + + create + + + ${noServer} + ${basedir}/target/server1 + ${basedir}/target/classes/activemq/server1 + + + + start0 + + cli + + + ${noServer} + true + ${basedir}/target/server0 + tcp://localhost:61616 + + run + + server0 + + + + start1 + + cli + + + ${noServer} + true + ${basedir}/target/server1 + tcp://localhost:61617 + + run + + server1 + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.ClusteredQueueExample + + + + stop0 + + cli + + + ${noServer} + ${basedir}/target/server0 + + stop + + + + + stop1 + + cli + + + ${noServer} + ${basedir}/target/server1 + + stop + + + + + + + org.apache.activemq.examples.jms + clustered-queue + ${project.version} + + + + + diff --git a/examples/jms/clustered-queue/readme.html b/examples/jms/clustered-queue/readme.html index 60ebd89d75..d89ed24d9e 100644 --- a/examples/jms/clustered-queue/readme.html +++ b/examples/jms/clustered-queue/readme.html @@ -27,6 +27,8 @@ under the License.

    JMS Load Balanced Clustered Queue Example

    +
    To run the example, simply type mvn verify from this directory, 
    or mvn -PnoServer verify if you want to start and create the server manually.
    +

    This example demonstrates a JMS queue deployed on two different nodes. The two nodes are configured to form a cluster.

    We then create a consumer on the queue on each node, and we create a producer on only one of the nodes.

    We then send some messages via the producer, and we verify that both consumers receive the sent messages @@ -50,147 +52,5 @@ under the License.

    For more information on ActiveMQ Artemis load balancing, and clustering in general, please see the clustering section of the user manual.

    -

    Example step-by-step

    -

    To run the example, simply type mvn verify -Pexample from this directory

    - -
      -
    1. Get an initial context for looking up JNDI from server 0.
    2. -
      -           
      -   ic0 = getContext(0);
      -   
      -        
      - -
    3. Look-up the JMS Queue object from JNDI
    4. -
      -           Queue queue = (Queue)ic0.lookup("/queue/exampleQueue");
      -        
      - -
    5. Look-up a JMS Connection Factory object from JNDI on server 0
    6. -
      -           ConnectionFactory cf0 = (ConnectionFactory)ic0.lookup("/ConnectionFactory");
      -        
      - -
    7. Get an initial context for looking up JNDI from server 1.
    8. -
      -           ic1 = getContext(1);
      -        
      - -
    9. Look-up a JMS Connection Factory object from JNDI on server 1
    10. -
      -           ConnectionFactory cf1 = (ConnectionFactory)ic1.lookup("/ConnectionFactory");
      -           
      -        
      - -
    11. We create a JMS Connection connection0 which is a connection to server 0
    12. -
      -          
      -   connection0 = cf0.createConnection();
      -          
      -        
      - -
    13. We create a JMS Connection connection1 which is a connection to server 1
    14. -
      -          
      -   connection1 = cf1.createConnection();
      -          
      -        
      - -
    15. We create a JMS Session on server 0
    16. -
      -           
      -   Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE);
      -           
      -        
      - -
    17. We create a JMS Session on server 1
    18. -
      -           
      -   Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
      -            
      -        
      - -
    19. We start the connections to ensure delivery occurs on them
    20. -
      -           
      -   connection0.start();
      -
      -   connection1.start();
      -           
      -        
      - -
    21. We create JMS MessageConsumer objects on server 0 and server 1
    22. -
      -           
      -   MessageConsumer consumer0 = session0.createConsumer(queue);
      -
      -   MessageConsumer consumer1 = session1.createConsumer(queue);
      -           
      -        
      - -
    23. We create a JMS MessageProducer object on server 0.
    24. -
      -           
      -   MessageProducer producer = session0.createProducer(queue);
      -        
      - -
    25. We send some messages to server 0.
    26. -
      -           
      -	final int numMessages = 10;
      -
      -	for (int i = 0; i < numMessages; i++)
      -	{
      -	   TextMessage message = session0.createTextMessage("This is text message " + i);
      -
      -	   producer.send(message);
      -
      -	   System.out.println("Sent message: " + message.getText());
      -	}
      -           
      -        
      - -
    27. We now consume those messages on *both* server 0 and server 1. - We note the messages have been distributed between servers in a round robin fashion. - ActiveMQ Artemis has load balanced the messages between the available consumers on the different nodes. - ActiveMQ Artemis can be configured to always load balance messages to all nodes, or to only balance messages - to nodes which have consumers with no or matching selectors. See the user manual for more details.
    28. - JMS Queues implement point-to-point message where each message is only ever consumed by a - maximum of one consumer. -
      -           
      -	for (int i = 0; i < numMessages; i += 2)
      -	{
      -	   TextMessage message0 = (TextMessage)consumer0.receive(5000);
      -
      -	   System.out.println("Got message: " + message0.getText() + " from node 0");
      -
      -	   TextMessage message1 = (TextMessage)consumer1.receive(5000);
      -
      -	   System.out.println("Got message: " + message1.getText() + " from node 1");
      -	}
      -           
      -        
      - -
    29. And finally (no pun intended), always remember to close your JMS resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
    30. - -
      -           
      -	finally
      -	{
      -	   if (connection0 != null)
      -	   {
      -	      connection0.close();
      -	   }
      -
      -	   if (connection1 != null)
      -	   {
      -	      connection1.close();
      -	   }
      -	}
      -           
      -        
      - -
    diff --git a/examples/jms/clustered-queue/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredQueueExample.java b/examples/jms/clustered-queue/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredQueueExample.java index 12a0a4554c..1ee779ac9a 100644 --- a/examples/jms/clustered-queue/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredQueueExample.java +++ b/examples/jms/clustered-queue/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredQueueExample.java @@ -23,8 +23,10 @@ import javax.jms.MessageProducer; import javax.jms.Queue; import javax.jms.Session; import javax.jms.TextMessage; -import javax.naming.InitialContext; -import java.util.Hashtable; + +import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; +import org.apache.activemq.artemis.jms.client.ActiveMQQueue; /** * A simple example that demonstrates server side load-balancing of messages between the queue instances on different @@ -38,33 +40,16 @@ public class ClusteredQueueExample Connection connection1 = null; - InitialContext ic0 = null; - - InitialContext ic1 = null; - try { - // Step 1. Get an initial context for looking up JNDI from server 0 - Hashtable properties = new Hashtable(); - properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); - properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61616"); - properties.put("queue.queue/exampleQueue", "exampleQueue"); - ic0 = new InitialContext(properties); + // Step 2. Instantiate the Queue + Queue queue = ActiveMQJMSClient.createQueue("exampleQueue"); - // Step 2. Look-up the JMS Queue object from JNDI - Queue queue = (Queue)ic0.lookup("queue/exampleQueue"); - - // Step 3. Look-up a JMS Connection Factory object from JNDI on server 0 - ConnectionFactory cf0 = (ConnectionFactory)ic0.lookup("ConnectionFactory"); - - // Step 4. Get an initial context for looking up JNDI from server 1 - properties = new Hashtable(); - properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); - properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61617"); - ic1 = new InitialContext(properties); + // Instantiate connection towards server 0 + ConnectionFactory cf0 = new ActiveMQConnectionFactory("tcp://localhost:61616"); // Step 5. Look-up a JMS Connection Factory object from JNDI on server 1 - ConnectionFactory cf1 = (ConnectionFactory)ic1.lookup("ConnectionFactory"); + ConnectionFactory cf1 = new ActiveMQConnectionFactory("tcp://localhost:61617"); // Step 6. We create a JMS Connection connection0 which is a connection to server 0 connection0 = cf0.createConnection(); @@ -135,16 +120,6 @@ public class ClusteredQueueExample { connection1.close(); } - - if (ic0 != null) - { - ic0.close(); - } - - if (ic1 != null) - { - ic1.close(); - } } } } diff --git a/examples/jms/clustered-queue/src/main/resources/activemq/server0/broker.xml b/examples/jms/clustered-queue/src/main/resources/activemq/server0/broker.xml index db9707688d..eb30a9096d 100644 --- a/examples/jms/clustered-queue/src/main/resources/activemq/server0/broker.xml +++ b/examples/jms/clustered-queue/src/main/resources/activemq/server0/broker.xml @@ -29,13 +29,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/clustered-standalone/pom.xml b/examples/jms/clustered-standalone/pom.xml deleted file mode 100644 index e37336f0db..0000000000 --- a/examples/jms/clustered-standalone/pom.xml +++ /dev/null @@ -1,188 +0,0 @@ - - - - - 4.0.0 - - - org.apache.activemq.examples.jms - jms-examples - 1.0.1-SNAPSHOT - - - artemis-jms-clustered-standalone-example - jar - ActiveMQ Artemis JMS Clustered Standalone Example - - - ${project.basedir}/../../.. - - - - - org.apache.geronimo.specs - geronimo-jms_2.0_spec - - - - - - example - - - - org.apache.activemq - artemis-maven-plugin - - - create0 - - create - - - ${basedir}/target/server0 - ${basedir}/target/classes/activemq/server0 - - - - create1 - - create - - - ${basedir}/target/server1 - ${basedir}/target/classes/activemq/server1 - - - - create2 - - create - - - ${basedir}/target/server2 - ${basedir}/target/classes/activemq/server2 - - - - start0 - - cli - - - true - ${basedir}/target/server0 - tcp://localhost:61616 - - run - - server0 - - - - start1 - - cli - - - true - ${basedir}/target/server1 - tcp://localhost:61617 - - run - - server1 - - - - start2 - - cli - - - true - ${basedir}/target/server2 - tcp://localhost:61618 - - run - - server2 - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.ClusteredStandaloneExample - - - - stop0 - - cli - - - ${basedir}/target/server0 - - stop - - - - - stop1 - - cli - - - ${basedir}/target/server1 - - stop - - - - - stop2 - - cli - - - ${basedir}/target/server2 - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-clustered-standalone-example - ${project.version} - - - - - - - - - diff --git a/examples/jms/clustered-standalone/readme.html b/examples/jms/clustered-standalone/readme.html deleted file mode 100644 index b72aa77661..0000000000 --- a/examples/jms/clustered-standalone/readme.html +++ /dev/null @@ -1,70 +0,0 @@ - - - - - JMS Clustered Stand-alone Example - - - - - -

    JMS Clustered Stand-alone Example

    - -

    This example demonstrates a JMS Topic deployed on three different nodes. - The three nodes are configured to form a cluster.

    -

    Subscribers for the topic are created on each node, and a producer is created on only one of the nodes.

    -

    Some messages are sent by the producer, and we verify that all subscribers receive all the - sent messages.

    -

    This example uses ActiveMQ's default stand-alone clustered configuration. - The relevant snippet from the server configuration, which tells the servers to form a cluster between the three nodes - and to load balance the messages between the nodes is:

    -
    -     <cluster-connection name="my-cluster">
    -        <address>jms</address>
    -        <discovery-group-ref discovery-group-name="dg-group1"/>
    -     </cluster-connection>
    -     
    -     
    -

    Example step-by-step

    -

    To run the example, simply type mvn verify -Pexample from this directory. This will - automatically start the 3 cluster nodes, each with its specific configuration.

    -

    To start the tests manually, the following steps are:

    -
      -
    • create 4 terminals (3 for the servers and 1 for the example client)
    • -
    • in the first terminal, go to the bin directory and start the first server (with default configuration): -
      ./run.sh ../config/stand-alone/clustered
      -
    • in the second terminal, start the second server: -
      export CLUSTER_PROPS="-Ddata.dir=../data-server2 -Djnp.port=2099 -Djnp.rmiPort=2098 -Dactivemq.remoting.netty.port=6445 -Dactivemq.remoting.netty.batch.port=6455"
      -./run.sh ../config/stand-alone/clustered
      -
    • in the third terminal, start the third server (with default configuration): -
      export CLUSTER_PROPS="-Ddata.dir=../data-server3 -Djnp.port=3099 -Djnp.rmiPort=3098 -Dactivemq.remoting.netty.port=7445 -Dactivemq.remoting.netty.batch.port=7455"
      -./run.sh ../config/stand-alone/clustered
      -
    • finally, in the fourth terminal, start the example -
      ./build.sh runRemote (or build.bat runRemote on windows)
      -

      The example connects to the three cluster nodes using JNDI (which are retrieved from - server0, server1, and - server2' s JNDI properties file). The JNDI ports were specified - using the environment property jnp.port (or 1098 by default) when starting the 3 cluster nodes.

      - -

      For a description of the example code, please read the - clustered-topic example which is very similar (it has 2 nodes while this example has 3 nodes). - - - diff --git a/examples/jms/clustered-standalone/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredStandaloneExample.java b/examples/jms/clustered-standalone/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredStandaloneExample.java deleted file mode 100644 index 59427f8b4a..0000000000 --- a/examples/jms/clustered-standalone/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredStandaloneExample.java +++ /dev/null @@ -1,181 +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. - */ -package org.apache.activemq.artemis.jms.example; - -import javax.jms.Connection; -import javax.jms.ConnectionFactory; -import javax.jms.MessageConsumer; -import javax.jms.MessageProducer; -import javax.jms.Session; -import javax.jms.TextMessage; -import javax.jms.Topic; -import javax.naming.InitialContext; -import java.util.Hashtable; - -public class ClusteredStandaloneExample -{ - public static void main(final String[] args) throws Exception - { - Connection connection0 = null; - - Connection connection1 = null; - - Connection connection2 = null; - - InitialContext initialContext0 = null; - InitialContext initialContext1 = null; - InitialContext initialContext2 = null; - - try - { - Hashtable properties = new Hashtable(); - properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); - properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61616"); - properties.put("topic.topic/exampleTopic", "exampleTopic"); - initialContext0 = new InitialContext(properties); - - properties = new Hashtable(); - properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); - properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61617"); - initialContext1 = new InitialContext(properties); - - properties = new Hashtable(); - properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); - properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61618"); - initialContext2 = new InitialContext(properties); - - // First we demonstrate a distributed topic. - // We create a connection on each node, create a consumer on each connection and send some - // messages at a node and verify they are all received by all consumers - - ConnectionFactory cf0 = (ConnectionFactory)initialContext0.lookup("ConnectionFactory"); - - System.out.println("Got cf " + cf0); - - ConnectionFactory cf1 = (ConnectionFactory)initialContext1.lookup("ConnectionFactory"); - - System.out.println("Got cf " + cf1); - - ConnectionFactory cf2 = (ConnectionFactory)initialContext2.lookup("ConnectionFactory"); - - System.out.println("Got cf " + cf2); - - Topic topic = (Topic)initialContext0.lookup("topic/exampleTopic"); - - connection0 = cf0.createConnection(); - - connection1 = cf1.createConnection(); - - connection2 = cf2.createConnection(); - - connection0.start(); - - connection1.start(); - - connection2.start(); - - Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE); - - Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE); - - Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE); - - MessageConsumer messageConsumer0 = session0.createConsumer(topic); - - MessageConsumer messageConsumer1 = session1.createConsumer(topic); - - MessageConsumer messageConsumer2 = session2.createConsumer(topic); - - MessageProducer producer = session0.createProducer(topic); - - final int numMessages = 10; - - for (int i = 0; i < numMessages; i++) - { - TextMessage message = session0.createTextMessage("Message " + i); - - producer.send(message); - } - - for (int i = 0; i < numMessages; i++) - { - TextMessage message0 = (TextMessage)messageConsumer0.receive(2000); - - if (message0 == null) - { - throw new IllegalStateException(); - } - - // System.out.println("Received message " + message0.getText()); - - TextMessage message1 = (TextMessage)messageConsumer1.receive(2000); - - if (message1 == null) - { - throw new IllegalStateException(); - } - - // System.out.println("Received message " + message1.getText()); - - TextMessage message2 = (TextMessage)messageConsumer2.receive(2000); - - if (message2 == null) - { - throw new IllegalStateException(); - } - - System.out.println("Received message " + message2.getText()); - } - - producer.close(); - - messageConsumer0.close(); - - messageConsumer1.close(); - - messageConsumer2.close(); - } - finally - { - // Step 12. Be sure to close our JMS resources! - if (initialContext0 != null) - { - initialContext0.close(); - } - if (initialContext1 != null) - { - initialContext1.close(); - } - if (initialContext2 != null) - { - initialContext2.close(); - } - if (connection0 != null) - { - connection0.close(); - } - if (connection1 != null) - { - connection1.close(); - } - if (connection2 != null) - { - connection2.close(); - } - } - } -} diff --git a/examples/jms/clustered-standalone/src/main/resources/activemq/server0/broker.xml b/examples/jms/clustered-standalone/src/main/resources/activemq/server0/broker.xml deleted file mode 100644 index 55675d0095..0000000000 --- a/examples/jms/clustered-standalone/src/main/resources/activemq/server0/broker.xml +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - - - - - - - - ${data.dir:./data}/bindings - - ${data.dir:./data}/journal - - ${data.dir:./data}/largemessages - - ${data.dir:./data}/paging - - - - tcp://localhost:61616 - - - - - tcp://localhost:61616 - - - - - - ${udp-address:231.7.7.7} - 9876 - 100 - netty-connector - - - - - - ${udp-address:231.7.7.7} - 9876 - 10000 - - - - - -

      jms
      - netty-connector - 500 - true - STRICT - 1 - - - - - - - - - - - - - - - - - - - - diff --git a/examples/jms/clustered-standalone/src/main/resources/activemq/server1/broker.xml b/examples/jms/clustered-standalone/src/main/resources/activemq/server1/broker.xml deleted file mode 100644 index 78b0f2f8f3..0000000000 --- a/examples/jms/clustered-standalone/src/main/resources/activemq/server1/broker.xml +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - - - - - - - - ${data.dir:./data}/bindings - - ${data.dir:./data}/journal - - ${data.dir:./data}/largemessages - - ${data.dir:./data}/paging - - - - tcp://localhost:61617 - - - - - tcp://localhost:61617 - - - - - - ${udp-address:231.7.7.7} - 9876 - 100 - netty-connector - - - - - - ${udp-address:231.7.7.7} - 9876 - 10000 - - - - - -
      jms
      - netty-connector - 500 - true - STRICT - 1 - -
      -
      - - - - - - - - - - - - - - - -
      -
      diff --git a/examples/jms/clustered-standalone/src/main/resources/activemq/server2/broker.xml b/examples/jms/clustered-standalone/src/main/resources/activemq/server2/broker.xml deleted file mode 100644 index 389914cce9..0000000000 --- a/examples/jms/clustered-standalone/src/main/resources/activemq/server2/broker.xml +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - - - - - - - - ${data.dir:./data}/bindings - - ${data.dir:./data}/journal - - ${data.dir:./data}/largemessages - - ${data.dir:./data}/paging - - - - tcp://localhost:61618 - - - - - tcp://localhost:61618 - - - - - - ${udp-address:231.7.7.7} - 9876 - 100 - netty-connector - - - - - - ${udp-address:231.7.7.7} - 9876 - 10000 - - - - - -
      jms
      - netty-connector - 500 - true - STRICT - 1 - -
      -
      - - - - - - - - - - - - - - - -
      -
      diff --git a/examples/jms/clustered-static-discovery/pom.xml b/examples/jms/clustered-static-discovery/pom.xml index 98fcc909a0..7a86bf788f 100644 --- a/examples/jms/clustered-static-discovery/pom.xml +++ b/examples/jms/clustered-static-discovery/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-clustered-static-discovery-example + clustered-static-discovery jar ActiveMQ Artemis JMS Clustered Static Discovery Example @@ -42,189 +43,206 @@ under the License. ${project.version} - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create0 - - create - - - ${basedir}/target/server0 - ${basedir}/target/classes/activemq/server0 - - - - create1 - - create - - - ${basedir}/target/server1 - ${basedir}/target/classes/activemq/server1 - - - - create2 - - create - - - ${basedir}/target/server2 - ${basedir}/target/classes/activemq/server2 - - - - create3 - - create - - - ${basedir}/target/server3 - ${basedir}/target/classes/activemq/server3 - - - - start0 - - cli - - - true - ${basedir}/target/server0 - tcp://localhost:61616 - - run - - server0 - - - - start1 - - cli - - - true - ${basedir}/target/server1 - tcp://localhost:61617 - - run - - server1 - - - - start2 - - cli - - - true - ${basedir}/target/server2 - tcp://localhost:61618 - - run - - server2 - - - - start3 - - cli - - - true - ${basedir}/target/server3 - tcp://localhost:61619 - - run - - server3 - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.StaticClusteredQueueExample - - - - stop0 - - cli - - - ${basedir}/target/server0 - - stop - - - - - stop1 - - cli - - - ${basedir}/target/server1 - - stop - - - - - stop2 - - cli - - - ${basedir}/target/server2 - - stop - - - - - stop3 - - cli - - - ${basedir}/target/server3 - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-clustered-static-discovery-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create0 + + create + + + ${noServer} + ${basedir}/target/server0 + ${basedir}/target/classes/activemq/server0 + + + + create1 + + create + + + ${noServer} + ${basedir}/target/server1 + ${basedir}/target/classes/activemq/server1 + + + + create2 + + create + + + ${noServer} + ${basedir}/target/server2 + ${basedir}/target/classes/activemq/server2 + + + + create3 + + create + + + ${noServer} + ${basedir}/target/server3 + ${basedir}/target/classes/activemq/server3 + + + + start0 + + cli + + + ${noServer} + true + ${basedir}/target/server0 + tcp://localhost:61616 + + run + + server0 + + + + start1 + + cli + + + true + ${noServer} + ${basedir}/target/server1 + tcp://localhost:61617 + + run + + server1 + + + + start2 + + cli + + + ${noServer} + true + ${basedir}/target/server2 + tcp://localhost:61618 + + run + + server2 + + + + start3 + + cli + + + ${noServer} + true + ${basedir}/target/server3 + tcp://localhost:61619 + + run + + server3 + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.StaticClusteredQueueExample + + + + stop0 + + cli + + + ${noServer} + ${basedir}/target/server0 + + stop + + + + + stop1 + + cli + + + ${noServer} + ${basedir}/target/server1 + + stop + + + + + stop2 + + cli + + + ${noServer} + ${basedir}/target/server2 + + stop + + + + + stop3 + + cli + + + ${noServer} + ${basedir}/target/server3 + + stop + + + + + + + org.apache.activemq.examples.jms + clustered-static-discovery + ${project.version} + + + + + diff --git a/examples/jms/clustered-static-discovery/readme.html b/examples/jms/clustered-static-discovery/readme.html index 71a4501d46..c1347dcdfe 100644 --- a/examples/jms/clustered-static-discovery/readme.html +++ b/examples/jms/clustered-static-discovery/readme.html @@ -26,6 +26,7 @@ under the License.

      JMS Load Balanced Static Clustered Queue Example

      +
      To run the example, simply type mvn verify from this directory, 
      or mvn -PnoServer verify if you want to start and create the server manually.

      This example demonstrates a JMS queue deployed on two different nodes. The two nodes are configured to form a cluster from a static list of nodes.

      @@ -53,147 +54,5 @@ under the License.

      For more information on ActiveMQ Artemis load balancing, and clustering in general, please see the clustering section of the user manual.

      -

      Example step-by-step

      -

      To run the example, simply type mvn verify -Pexample from this directory

      - -
        -
      1. Get an initial context for looking up JNDI from server 0.
      2. -
        -           
        -   ic0 = getContext(0);
        -   
        -        
        - -
      3. Look-up the JMS Queue object from JNDI
      4. -
        -           Queue queue = (Queue)ic0.lookup("/queue/exampleQueue");
        -        
        - -
      5. Look-up a JMS Connection Factory object from JNDI on server 0
      6. -
        -           ConnectionFactory cf0 = (ConnectionFactory)ic0.lookup("/ConnectionFactory");
        -        
        - -
      7. Get an initial context for looking up JNDI from server 1.
      8. -
        -           ic1 = getContext(1);
        -        
        - -
      9. Look-up a JMS Connection Factory object from JNDI on server 1
      10. -
        -           ConnectionFactory cf1 = (ConnectionFactory)ic1.lookup("/ConnectionFactory");
        -           
        -        
        - -
      11. We create a JMS Connection connection0 which is a connection to server 0
      12. -
        -          
        -   connection0 = cf0.createConnection();
        -          
        -        
        - -
      13. We create a JMS Connection connection1 which is a connection to server 1
      14. -
        -          
        -   connection1 = cf1.createConnection();
        -          
        -        
        - -
      15. We create a JMS Session on server 0
      16. -
        -           
        -   Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE);
        -           
        -        
        - -
      17. We create a JMS Session on server 1
      18. -
        -           
        -   Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
        -            
        -        
        - -
      19. We start the connections to ensure delivery occurs on them
      20. -
        -           
        -   connection0.start();
        -
        -   connection1.start();
        -           
        -        
        - -
      21. We create JMS MessageConsumer objects on server 0 and server 1
      22. -
        -           
        -   MessageConsumer consumer0 = session0.createConsumer(queue);
        -
        -   MessageConsumer consumer1 = session1.createConsumer(queue);
        -           
        -        
        - -
      23. We create a JMS MessageProducer object on server 0.
      24. -
        -           
        -   MessageProducer producer = session0.createProducer(queue);
        -        
        - -
      25. We send some messages to server 0.
      26. -
        -           
        -	final int numMessages = 10;
        -
        -	for (int i = 0; i < numMessages; i++)
        -	{
        -	   TextMessage message = session0.createTextMessage("This is text message " + i);
        -
        -	   producer.send(message);
        -
        -	   System.out.println("Sent message: " + message.getText());
        -	}
        -           
        -        
        - -
      27. We now consume those messages on *both* server 0 and server 1. - We note the messages have been distributed between servers in a round robin fashion. - ActiveMQ Artemis has load balanced the messages between the available consumers on the different nodes. - ActiveMQ Artemis can be configured to always load balance messages to all nodes, or to only balance messages - to nodes which have consumers with no or matching selectors. See the user manual for more details.
      28. - JMS Queues implement point-to-point message where each message is only ever consumed by a - maximum of one consumer. -
        -           
        -	for (int i = 0; i < numMessages; i += 2)
        -	{
        -	   TextMessage message0 = (TextMessage)consumer0.receive(5000);
        -
        -	   System.out.println("Got message: " + message0.getText() + " from node 0");
        -
        -	   TextMessage message1 = (TextMessage)consumer1.receive(5000);
        -
        -	   System.out.println("Got message: " + message1.getText() + " from node 1");
        -	}
        -           
        -        
        - -
      29. And finally (no pun intended), always remember to close your JMS resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
      30. - -
        -           
        -	finally
        -	{
        -	   if (connection0 != null)
        -	   {
        -	      connection0.close();
        -	   }
        -
        -	   if (connection1 != null)
        -	   {
        -	      connection1.close();
        -	   }
        -	}
        -           
        -        
        - -
      diff --git a/examples/jms/clustered-static-discovery/src/main/java/org/apache/activemq/artemis/jms/example/StaticClusteredQueueExample.java b/examples/jms/clustered-static-discovery/src/main/java/org/apache/activemq/artemis/jms/example/StaticClusteredQueueExample.java index 4e0ac264cd..6716075085 100644 --- a/examples/jms/clustered-static-discovery/src/main/java/org/apache/activemq/artemis/jms/example/StaticClusteredQueueExample.java +++ b/examples/jms/clustered-static-discovery/src/main/java/org/apache/activemq/artemis/jms/example/StaticClusteredQueueExample.java @@ -16,8 +16,6 @@ */ 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; @@ -25,8 +23,10 @@ import javax.jms.MessageProducer; import javax.jms.Queue; import javax.jms.Session; import javax.jms.TextMessage; -import javax.naming.InitialContext; -import java.util.Hashtable; + +import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; +import org.apache.activemq.artemis.util.ServerUtil; /** * A simple example that demonstrates server side load-balancing of messages between the queue instances on different @@ -46,22 +46,13 @@ public class StaticClusteredQueueExample Connection connection3 = null; - InitialContext ic0 = null; - try { - // Step 1. Get an initial context for looking up JNDI from server 3 - Hashtable properties = new Hashtable(); - properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); - properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61619"); - properties.put("queue.queue/exampleQueue", "exampleQueue"); - ic0 = new InitialContext(properties); + // Step 2. Use direct instantiation (or JNDI if you like) + Queue queue = ActiveMQJMSClient.createQueue("exampleQueue"); - // Step 2. Look-up the JMS Queue object from JNDI - Queue queue = (Queue)ic0.lookup("queue/exampleQueue"); - - // Step 3. Look-up a JMS Connection Factory object from JNDI on server 0 - ConnectionFactory cf0 = (ConnectionFactory)ic0.lookup("ConnectionFactory"); + // Step 3. new JMS Connection Factory object from JNDI on server 3 + ConnectionFactory cf0 = new ActiveMQConnectionFactory("tcp://localhost:61619"); //grab an initial connection and wait, in reality you wouldn't do it this way but since we want to ensure an // equal load balance we do this and then create 4 connections round robined @@ -189,11 +180,6 @@ public class StaticClusteredQueueExample { connection3.close(); } - - if (ic0 != null) - { - ic0.close(); - } } } } diff --git a/examples/jms/clustered-static-discovery/src/main/resources/activemq/server0/broker.xml b/examples/jms/clustered-static-discovery/src/main/resources/activemq/server0/broker.xml index 30bee5dcf7..b1bfd11f6f 100644 --- a/examples/jms/clustered-static-discovery/src/main/resources/activemq/server0/broker.xml +++ b/examples/jms/clustered-static-discovery/src/main/resources/activemq/server0/broker.xml @@ -29,13 +29,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/clustered-static-discovery/src/main/resources/activemq/server1/broker.xml b/examples/jms/clustered-static-discovery/src/main/resources/activemq/server1/broker.xml index f2f2565841..04125765d6 100644 --- a/examples/jms/clustered-static-discovery/src/main/resources/activemq/server1/broker.xml +++ b/examples/jms/clustered-static-discovery/src/main/resources/activemq/server1/broker.xml @@ -29,13 +29,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/clustered-static-discovery/src/main/resources/activemq/server2/broker.xml b/examples/jms/clustered-static-discovery/src/main/resources/activemq/server2/broker.xml index e9e5f08ba0..98b8f04430 100644 --- a/examples/jms/clustered-static-discovery/src/main/resources/activemq/server2/broker.xml +++ b/examples/jms/clustered-static-discovery/src/main/resources/activemq/server2/broker.xml @@ -26,13 +26,13 @@ - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/clustered-static-discovery/src/main/resources/activemq/server3/broker.xml b/examples/jms/clustered-static-discovery/src/main/resources/activemq/server3/broker.xml index 0ebc2d0064..40bef8798d 100644 --- a/examples/jms/clustered-static-discovery/src/main/resources/activemq/server3/broker.xml +++ b/examples/jms/clustered-static-discovery/src/main/resources/activemq/server3/broker.xml @@ -26,13 +26,13 @@ - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/clustered-static-oneway/pom.xml b/examples/jms/clustered-static-oneway/pom.xml index 991a6248f3..f3d8db5679 100644 --- a/examples/jms/clustered-static-oneway/pom.xml +++ b/examples/jms/clustered-static-oneway/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-clustered-static-oneway-example + clustered-static-oneway jar ActiveMQ Artemis JMS Clustered Static One Way Example @@ -42,151 +43,165 @@ under the License. ${project.version} - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create0 - - create - - - ${basedir}/target/server0 - ${basedir}/target/classes/activemq/server0 - - - - create1 - - create - - - ${basedir}/target/server1 - ${basedir}/target/classes/activemq/server1 - - - - create2 - - create - - - ${basedir}/target/server2 - ${basedir}/target/classes/activemq/server2 - - - - start0 - - cli - - - true - ${basedir}/target/server0 - tcp://localhost:61616 - - run - - server0 - - - - start1 - - cli - - - true - ${basedir}/target/server1 - tcp://localhost:61617 - - run - - server1 - - - - start2 - - cli - - - true - ${basedir}/target/server2 - tcp://localhost:61618 - - run - - server2 - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.ClusterStaticOnewayExample - - - - stop0 - - cli - - - ${basedir}/target/server0 - - stop - - - - - stop1 - - cli - - - ${basedir}/target/server1 - - stop - - - - - stop2 - - cli - - - ${basedir}/target/server2 - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-clustered-static-oneway-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create0 + + create + + + ${noServer} + ${basedir}/target/server0 + ${basedir}/target/classes/activemq/server0 + + + + create1 + + create + + + ${noServer} + ${basedir}/target/server1 + ${basedir}/target/classes/activemq/server1 + + + + create2 + + create + + + ${noServer} + ${basedir}/target/server2 + ${basedir}/target/classes/activemq/server2 + + + + start0 + + cli + + + ${noServer} + true + ${basedir}/target/server0 + tcp://localhost:61616 + + run + + server0 + + + + start1 + + cli + + + ${noServer} + true + ${basedir}/target/server1 + tcp://localhost:61617 + + run + + server1 + + + + start2 + + cli + + + ${noServer} + true + ${basedir}/target/server2 + tcp://localhost:61618 + + run + + server2 + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.ClusterStaticOnewayExample + + + + stop0 + + cli + + + ${noServer} + ${basedir}/target/server0 + + stop + + + + + stop1 + + cli + + + ${noServer} + ${basedir}/target/server1 + + stop + + + + + stop2 + + cli + + + ${noServer} + ${basedir}/target/server2 + + stop + + + + + + + org.apache.activemq.examples.jms + clustered-static-oneway + ${project.version} + + + + + diff --git a/examples/jms/clustered-static-oneway/readme.html b/examples/jms/clustered-static-oneway/readme.html index 4aacbbdbd3..d19ba03f62 100644 --- a/examples/jms/clustered-static-oneway/readme.html +++ b/examples/jms/clustered-static-oneway/readme.html @@ -26,6 +26,7 @@ under the License.

      JMS Load Balanced Static Clustered One Way Queue Example

      +
      To run the example, simply type mvn verify from this directory, 
      or mvn -PnoServer verify if you want to start and create the server manually.

      This example demonstrates a JMS queue deployed on three different nodes. The three nodes are configured to form a one way cluster from a static list of nodes.

      @@ -59,190 +60,5 @@ under the License.

      For more information on ActiveMQ Artemis load balancing, and clustering in general, please see the clustering section of the user manual.

      -

      Example step-by-step

      -

      To run the example, simply type mvn verify -Pexample from this directory

      - -
        -
      1. Get an initial context for looking up JNDI from server 0.
      2. -
        -           
        -   ic0 = getContext(0);
        -   
        -        
        - -
      3. Look-up the JMS Queue object from JNDI
      4. -
        -           
        -   Queue queue = (Queue)ic0.lookup("/queue/exampleQueue");
        -           
        -        
        - -
      5. Look-up a JMS Connection Factory object from JNDI on server 0
      6. -
        -           
        -   ConnectionFactory cf0 = (ConnectionFactory)ic0.lookup("/ConnectionFactory");
        -           
        -        
        - - -
      7. grab an initial connection and wait, in reality you wouldn't do it this way but since we want to ensure an - equal load balance we do this and then create 4 connections round robined
      8. -
        -           
        -   initialConnection = cf0.createConnection();
        -           
        -        
        - -
      9. We create a JMS Connection connection0 which is a connection to server 0
      10. -
        -           
        -   connection0 = cf0.createConnection()
        -           
        -        
        - -
      11. We create a JMS Connection connection0 which is a connection to server 1
      12. -
        -           
        -   connection1 = cf0.createConnection()
        -           
        -        
        - -
      13. We create a JMS Connection connection0 which is a connection to server 2
      14. -
        -           
        -   connection2 = cf0.createConnection()
        -           
        -        
        - -
      15. We create a JMS Session on server 0
      16. -
        -           
        -   Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE);
        -           
        -        
        - -
      17. We create a JMS Session on server 1
      18. -
        -           
        -   Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
        -            
        -        
        - -
      19. We create a JMS Session on server 1
      20. -
        -           
        -   Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
        -            
        -        
        -
      21. We start the connections to ensure delivery occurs on them
      22. -
        -           
        -   connection0.start();
        -
        -   connection1.start();
        -
        -   connection2.start();
        -           
        -        
        - - -
      23. We create JMS MessageConsumer objects on server 0 and server 1
      24. -
        -           
        -   MessageConsumer consumer0 = session0.createConsumer(queue);
        -
        -   MessageConsumer consumer2 = session2.createConsumer(queue);
        -
        -   MessageConsumer consumer3 = session3.createConsumer(queue);
        -           
        -        
        - - -
      25. We create a JMS MessageProducer object on server 0.
      26. -
        -           
        -   Session sendSession = getServerConnection(0, connection0, connection1, connection2).createSession(false, Session.AUTO_ACKNOWLEDGE);
        -
        -   MessageProducer producer = sendSession.createProducer(queue);
        -           
        -        
        - -
      27. We send some messages to server 0.
      28. -
        -           
        -	final int numMessages = 18;
        -
        -	for (int i = 0; i < numMessages; i++)
        -	{
        -	   TextMessage message = session0.createTextMessage("This is text message " + i);
        -
        -	   producer.send(message);
        -
        -	   System.out.println("Sent message: " + message.getText());
        -	}
        -           
        -        
        - -
      29. We now consume those messages on *both* server 0 and server 1. - We note the messages have been distributed between servers in a round robin fashion. - ActiveMQ Artemis has load balanced the messages between the available consumers on the different nodes. - ActiveMQ Artemis can be configured to always load balance messages to all nodes, or to only balance messages - to nodes which have consumers with no or matching selectors. See the user manual for more details.
      30. - JMS Queues implement point-to-point message where each message is only ever consumed by a - maximum of one consumer. -
        -           
        -	for (int i = 0; i < numMessages; i += 2)
        -	{
        -	   TextMessage message0 = (TextMessage)consumer0.receive(5000);
        -
        -	   System.out.println("Got message: " + message0.getText() + " from node 0");
        -
        -	   TextMessage message1 = (TextMessage)consumer1.receive(5000);
        -
        -	   System.out.println("Got message: " + message1.getText() + " from node 1");
        -
        -	   TextMessage message2 = (TextMessage)consumer2.receive(5000);
        -
        -	   System.out.println("Got message: " + message2.getText() + " from node " + con2Node);
        -	}
        -           
        -        
        - -
      31. And finally (no pun intended), always remember to close your JMS resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
      32. - -
        -           
        -    finally
        -    {
        -      if (initialConnection != null)
        -      {
        -         initialConnection.close();
        -      }
        -
        -      if (connection0 != null)
        -      {
        -         connection0.close();
        -      }
        -
        -      if (connection1 != null)
        -      {
        -         connection1.close();
        -      }
        -
        -      if (connection2 != null)
        -      {
        -         connection2.close();
        -      }
        -
        -      if (ic0 != null)
        -      {
        -         ic0.close();
        -      }
        -    }
        -           
        -        
        - -
      diff --git a/examples/jms/clustered-static-oneway/src/main/java/org/apache/activemq/artemis/jms/example/ClusterStaticOnewayExample.java b/examples/jms/clustered-static-oneway/src/main/java/org/apache/activemq/artemis/jms/example/ClusterStaticOnewayExample.java index e061722845..53d98bc8ec 100644 --- a/examples/jms/clustered-static-oneway/src/main/java/org/apache/activemq/artemis/jms/example/ClusterStaticOnewayExample.java +++ b/examples/jms/clustered-static-oneway/src/main/java/org/apache/activemq/artemis/jms/example/ClusterStaticOnewayExample.java @@ -16,8 +16,6 @@ */ 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; @@ -25,8 +23,10 @@ import javax.jms.MessageProducer; import javax.jms.Queue; import javax.jms.Session; import javax.jms.TextMessage; -import javax.naming.InitialContext; -import java.util.Hashtable; + +import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; +import org.apache.activemq.artemis.util.ServerUtil; /** * A simple example that demonstrates server side load-balancing of messages between the queue instances on different @@ -44,22 +44,13 @@ public class ClusterStaticOnewayExample Connection connection2 = null; - InitialContext ic0 = null; - try { - // Step 1. Get an initial context for looking up JNDI from server 0 - Hashtable properties = new Hashtable(); - properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); - properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61616"); - properties.put("queue.queue/exampleQueue", "exampleQueue"); - ic0 = new InitialContext(properties); - - // Step 2. Look-up the JMS Queue object from JNDI - Queue queue = (Queue)ic0.lookup("queue/exampleQueue"); + // Step 2. Instantiate Queue + Queue queue = ActiveMQJMSClient.createQueue("exampleQueue"); // Step 3. Look-up a JMS Connection Factory object from JNDI on server 0 - ConnectionFactory cf0 = (ConnectionFactory)ic0.lookup("ConnectionFactory"); + ConnectionFactory cf0 = new ActiveMQConnectionFactory("tcp://localhost:61616"); //step 4. grab an initial connection and wait, in reality you wouldn't do it this way but since we want to ensure an // equal load balance we do this and then create 4 connections round robined @@ -173,11 +164,6 @@ public class ClusterStaticOnewayExample { connection2.close(); } - - if (ic0 != null) - { - ic0.close(); - } } } } diff --git a/examples/jms/clustered-static-oneway/src/main/resources/activemq/server0/broker.xml b/examples/jms/clustered-static-oneway/src/main/resources/activemq/server0/broker.xml index 2d77bb142a..3e86ed3f4c 100644 --- a/examples/jms/clustered-static-oneway/src/main/resources/activemq/server0/broker.xml +++ b/examples/jms/clustered-static-oneway/src/main/resources/activemq/server0/broker.xml @@ -26,13 +26,13 @@ - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/clustered-static-oneway/src/main/resources/activemq/server1/broker.xml b/examples/jms/clustered-static-oneway/src/main/resources/activemq/server1/broker.xml index 9b5fdf8125..1464ea95f1 100644 --- a/examples/jms/clustered-static-oneway/src/main/resources/activemq/server1/broker.xml +++ b/examples/jms/clustered-static-oneway/src/main/resources/activemq/server1/broker.xml @@ -26,13 +26,13 @@ - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/clustered-static-oneway/src/main/resources/activemq/server2/broker.xml b/examples/jms/clustered-static-oneway/src/main/resources/activemq/server2/broker.xml index 147a9b9875..b1043f5c77 100644 --- a/examples/jms/clustered-static-oneway/src/main/resources/activemq/server2/broker.xml +++ b/examples/jms/clustered-static-oneway/src/main/resources/activemq/server2/broker.xml @@ -26,13 +26,13 @@ - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/clustered-topic/pom.xml b/examples/jms/clustered-topic/pom.xml index 418d98f32d..2982b219ff 100644 --- a/examples/jms/clustered-topic/pom.xml +++ b/examples/jms/clustered-topic/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-clustered-topic-example + clustered-topic jar ActiveMQ Artemis JMS Clustered Topic Example @@ -37,115 +38,125 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create0 - - create - - - ${basedir}/target/server0 - ${basedir}/target/classes/activemq/server0 - - - - create1 - - create - - - ${basedir}/target/server1 - ${basedir}/target/classes/activemq/server1 - - - - start0 - - cli - - - true - ${basedir}/target/server0 - tcp://localhost:61616 - - run - - server0 - - - - start1 - - cli - - - true - ${basedir}/target/server1 - tcp://localhost:61617 - - run - - server1 - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.ClusteredTopicExample - - - - stop0 - - cli - - - ${basedir}/target/server0 - - stop - - - - - stop1 - - cli - - - ${basedir}/target/server1 - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-clustered-topic-example - ${project.version} - - - - - + + noServer + + true + - + + + + org.apache.activemq + artemis-maven-plugin + + + create0 + + create + + + ${noServer} + ${basedir}/target/server0 + ${basedir}/target/classes/activemq/server0 + + + + create1 + + create + + + ${noServer} + ${basedir}/target/server1 + ${basedir}/target/classes/activemq/server1 + + + + start0 + + cli + + + ${noServer} + true + ${basedir}/target/server0 + tcp://localhost:61616 + + run + + server0 + + + + start1 + + cli + + + ${noServer} + true + ${basedir}/target/server1 + tcp://localhost:61617 + + run + + server1 + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.ClusteredTopicExample + + + + stop0 + + cli + + + ${noServer} + ${basedir}/target/server0 + + stop + + + + + stop1 + + cli + + + ${noServer} + ${basedir}/target/server1 + + stop + + + + + + + org.apache.activemq.examples.jms + clustered-topic + ${project.version} + + + + + diff --git a/examples/jms/clustered-topic/readme.html b/examples/jms/clustered-topic/readme.html index bf92e08db8..cd29bb46b3 100644 --- a/examples/jms/clustered-topic/readme.html +++ b/examples/jms/clustered-topic/readme.html @@ -26,6 +26,7 @@ under the License.

      JMS Clustered Topic Example

      +
      To run the example, simply type mvn verify from this directory, 
      or mvn -PnoServer verify if you want to start and create the server manually.

      This example demonstrates a JMS Topic deployed on two different nodes. The two nodes are configured to form a cluster.

      We then create a subscriber on the topic on each node, and we create a producer on only one of the nodes.

      @@ -50,144 +51,5 @@ under the License.

      For more information on ActiveMQ Artemis load balancing, and clustering in general, please see the clustering section of the user manual.

      -

      Example step-by-step

      -

      To run the example, simply type mvn verify -Pexample from this directory

      - -
        -
      1. Get an initial context for looking up JNDI from server 0.
      2. -
        -           
        -   ic0 = getContext(0);
        -   
        -        
        - -
      3. Look-up the JMS Topic object from JNDI
      4. -
        -           Topic topic = (Topic)ic0.lookup("/topic/exampleTopic");
        -        
        - -
      5. Look-up a JMS Connection Factory object from JNDI on server 0
      6. -
        -           ConnectionFactory cf0 = (ConnectionFactory)ic0.lookup("/ConnectionFactory");
        -        
        - -
      7. Get an initial context for looking up JNDI from server 1.
      8. -
        -           ic1 = getContext(1);
        -        
        - -
      9. Look-up a JMS Connection Factory object from JNDI on server 1
      10. -
        -           ConnectionFactory cf1 = (ConnectionFactory)ic1.lookup("/ConnectionFactory");
        -           
        -        
        - -
      11. We create a JMS Connection connection0 which is a connection to server 0
      12. -
        -          
        -   connection0 = cf0.createConnection();
        -          
        -        
        - -
      13. We create a JMS Connection connection1 which is a connection to server 1
      14. -
        -          
        -   connection1 = cf1.createConnection();
        -          
        -        
        - -
      15. We create a JMS Session on server 0
      16. -
        -           
        -   Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE);
        -           
        -        
        - -
      17. We create a JMS Session on server 1
      18. -
        -           
        -   Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
        -            
        -        
        - -
      19. We start the connections to ensure delivery occurs on them
      20. -
        -           
        -   connection0.start();
        -
        -   connection1.start();
        -           
        -        
        - -
      21. We create JMS MessageConsumer (Topic subscriber) objects on server 0 and server 1
      22. -
        -           
        -   MessageConsumer consumer0 = session0.createConsumer(topic);
        -
        -   MessageConsumer consumer1 = session1.createConsumer(topic);
        -           
        -        
        - -
      23. We create a JMS MessageProducer object on server 0.
      24. -
        -           
        -   MessageProducer producer = session0.createProducer(topic);
        -        
        - -
      25. We send some messages to server 0.
      26. -
        -           
        -	final int numMessages = 10;
        -
        -	for (int i = 0; i < numMessages; i++)
        -	{
        -	   TextMessage message = session0.createTextMessage("This is text message " + i);
        -
        -	   producer.send(message);
        -
        -	   System.out.println("Sent message: " + message.getText());
        -	}
        -           
        -        
        - -
      27. - We now consume those messages on both server 0 and server 1. - We note that all messages have been consumed by both consumers. - JMS Topics implement publish-subscribe messaging where all consumers get a copy of all messages. -
        -           
        -	for (int i = 0; i < numMessages; i ++)
        -	{
        -	   TextMessage message0 = (TextMessage)consumer0.receive(5000);
        -
        -	   System.out.println("Got message: " + message0.getText() + " from node 0");
        -
        -	   TextMessage message1 = (TextMessage)consumer1.receive(5000);
        -
        -	   System.out.println("Got message: " + message1.getText() + " from node 1");
        -	}
        -           
        -        
        - -
      28. And finally (no pun intended), always remember to close your JMS resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
      29. - -
        -           
        -	finally
        -	{
        -	   if (connection0 != null)
        -	   {
        -	      connection0.close();
        -	   }
        -
        -	   if (connection1 != null)
        -	   {
        -	      connection1.close();
        -	   }
        -	}
        -           
        -        
        - -
      diff --git a/examples/jms/clustered-topic/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredTopicExample.java b/examples/jms/clustered-topic/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredTopicExample.java index 31b3d412c5..a12fedd894 100644 --- a/examples/jms/clustered-topic/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredTopicExample.java +++ b/examples/jms/clustered-topic/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredTopicExample.java @@ -24,7 +24,9 @@ import javax.jms.Session; import javax.jms.TextMessage; import javax.jms.Topic; import javax.naming.InitialContext; -import java.util.Hashtable; + +import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; /** * A simple example that shows a JMS Topic clustered across two nodes of a cluster. @@ -44,56 +46,44 @@ public class ClusteredTopicExample try { - // Step 1. Get an initial context for looking up JNDI from server 0 - Hashtable properties = new Hashtable(); - properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); - properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61616"); - properties.put("topic.topic/exampleTopic", "exampleTopic"); - ic0 = new InitialContext(properties); - // Step 2. Look-up the JMS Topic object from JNDI - Topic topic = (Topic)ic0.lookup("topic/exampleTopic"); + // Step 1. Instantiate topic + Topic topic = ActiveMQJMSClient.createTopic("exampleTopic"); - // Step 3. Look-up a JMS Connection Factory object from JNDI on server 0 - ConnectionFactory cf0 = (ConnectionFactory)ic0.lookup("ConnectionFactory"); + // Step 2. Look-up a JMS Connection Factory object from JNDI on server 0 + ConnectionFactory cf0 = new ActiveMQConnectionFactory("tcp://localhost:61616"); - // Step 4. Get an initial context for looking up JNDI from server 1 - properties = new Hashtable(); - properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); - properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61617"); - ic1 = new InitialContext(properties); + // Step 3. Look-up a JMS Connection Factory object from JNDI on server 1 + ConnectionFactory cf1 = new ActiveMQConnectionFactory("tcp://localhost:61617"); - // Step 5. Look-up a JMS Connection Factory object from JNDI on server 1 - ConnectionFactory cf1 = (ConnectionFactory)ic1.lookup("ConnectionFactory"); - - // Step 6. We create a JMS Connection connection0 which is a connection to server 0 + // Step 4. We create a JMS Connection connection0 which is a connection to server 0 connection0 = cf0.createConnection(); - // Step 7. We create a JMS Connection connection1 which is a connection to server 1 + // Step 5. We create a JMS Connection connection1 which is a connection to server 1 connection1 = cf1.createConnection(); - // Step 8. We create a JMS Session on server 0 + // Step 6. We create a JMS Session on server 0 Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE); - // Step 9. We create a JMS Session on server 1 + // Step 7. We create a JMS Session on server 1 Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE); - // Step 10. We start the connections to ensure delivery occurs on them + // Step 8. We start the connections to ensure delivery occurs on them connection0.start(); connection1.start(); - // Step 11. We create JMS MessageConsumer objects on server 0 and server 1 + // Step 9. We create JMS MessageConsumer objects on server 0 and server 1 MessageConsumer consumer0 = session0.createConsumer(topic); MessageConsumer consumer1 = session1.createConsumer(topic); Thread.sleep(1000); - // Step 12. We create a JMS MessageProducer object on server 0 + // Step 10. We create a JMS MessageProducer object on server 0 MessageProducer producer = session0.createProducer(topic); - // Step 13. We send some messages to server 0 + // Step 11. We send some messages to server 0 final int numMessages = 10; @@ -106,7 +96,7 @@ public class ClusteredTopicExample System.out.println("Sent message: " + message.getText()); } - // Step 14. We now consume those messages on *both* server 0 and server 1. + // Step 12. We now consume those messages on *both* server 0 and server 1. // We note that all messages have been consumed by *both* consumers. // JMS Topics implement *publish-subscribe* messaging where all consumers get a copy of all messages diff --git a/examples/jms/clustered-topic/src/main/resources/activemq/server0/broker.xml b/examples/jms/clustered-topic/src/main/resources/activemq/server0/broker.xml index 452b412c27..a4e8ddef07 100644 --- a/examples/jms/clustered-topic/src/main/resources/activemq/server0/broker.xml +++ b/examples/jms/clustered-topic/src/main/resources/activemq/server0/broker.xml @@ -29,13 +29,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/clustered-topic/src/main/resources/activemq/server1/broker.xml b/examples/jms/clustered-topic/src/main/resources/activemq/server1/broker.xml index c1a763b150..78beec32d4 100644 --- a/examples/jms/clustered-topic/src/main/resources/activemq/server1/broker.xml +++ b/examples/jms/clustered-topic/src/main/resources/activemq/server1/broker.xml @@ -29,13 +29,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/colocated-failover-scale-down/pom.xml b/examples/jms/colocated-failover-scale-down/pom.xml index ea1fb1095a..d2947c4586 100644 --- a/examples/jms/colocated-failover-scale-down/pom.xml +++ b/examples/jms/colocated-failover-scale-down/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -42,65 +43,61 @@ under the License. ${project.version} - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - - - - example - - - - org.apache.activemq - artemis-maven-plugin - - - create0 - - create - - - ${basedir}/target/server0 - ${basedir}/target/classes/activemq/server0 - - - - create1 - - create - - - ${basedir}/target/server1 - ${basedir}/target/classes/activemq/server1 - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.ColocatedFailoverScaleDownExample - - ${basedir}/target/server0 - ${basedir}/target/server1 - - - - - - - org.apache.activemq.examples.jms - colocated-failover-scale-down - ${project.version} - - - - - - - + + + + org.apache.activemq + artemis-maven-plugin + + + create0 + + create + + + ${basedir}/target/server0 + ${basedir}/target/classes/activemq/server0 + + + + create1 + + create + + + ${basedir}/target/server1 + ${basedir}/target/classes/activemq/server1 + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.ColocatedFailoverScaleDownExample + + + ${basedir}/target/server0 + ${basedir}/target/server1 + + + + + + + org.apache.activemq.examples.jms + colocated-failover-scale-down + ${project.version} + + + + + diff --git a/examples/jms/colocated-failover-scale-down/readme.html b/examples/jms/colocated-failover-scale-down/readme.html index 46eeef6877..ffcd73b808 100644 --- a/examples/jms/colocated-failover-scale-down/readme.html +++ b/examples/jms/colocated-failover-scale-down/readme.html @@ -26,6 +26,8 @@ under the License.

      JMS Colocated Failover Recover Only Example

      +
      To run the example, simply type mvn verify from this directory. This example will always spawn and stop multiple servers.
      +

      This example demonstrates how you can colocate live and backup servers in the same VM. We do this by creating an HA Policy that is colocated. colocated means that backup servers can be created and maintained by live servers on behalf @@ -59,133 +61,5 @@ under the License. from the list of available connectors which in this case is the first INVM connector

      One other thing to notice is that the cluster connection has its reconnect attempts set to 5, this is so it will disconnect instead of trying to reconnect to a backup that doesn't exist.

      -

      Example step-by-step

      -

      To run the example, simply type mvn verify -Pexample from this directory

      - -
        -
      1. Get an initial context for looking up JNDI for both servers
      2. -
        -           
        -    initialContext1 = getContext(1);
        -    initialContext = getContext(0);
        -   
        -        
        - -
      3. Look up the JMS resources from JNDI
      4. -
        -           
        -    Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue");
        -    ConnectionFactory connectionFactory = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
        -    ConnectionFactory connectionFactory1 = (ConnectionFactory)initialContext1.lookup("/ConnectionFactory");
        -           
        -        
        - -
      5. Create a JMS Connections
      6. -
        -           
        -    connection = connectionFactory.createConnection();
        -    connection1 = connectionFactory1.createConnection();
        -           
        -        
        - -
      7. Create a *non-transacted* JMS Session with client acknowledgement
      8. -
        -           
        -    Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        -    Session session1 = connection1.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        -           
        -        
        - -
      9. Create a JMS MessageProducer
      10. -
        -           
        -    MessageProducer producer = session.createProducer(queue);
        -    MessageProducer producer1 = session1.createProducer(queue);
        -           
        -        
        - -
      11. Send some messages to both servers
      12. -
        -          
        -    for (int i = 0; i < numMessages; i++)
        -    {
        -      TextMessage message = session.createTextMessage("This is text message " + i);
        -      producer.send(message);
        -      System.out.println("Sent message: " + message.getText());
        -      message = session1.createTextMessage("This is another text message " + i);
        -      producer1.send(message);
        -      System.out.println("Sent message: " + message.getText());
        -    }
        -          
        -        
        - -
      13. Crash server #0, the live server
      14. -
        -          
        -    killServer(0);
        -          
        -        
        - -
      15. start the connection ready to receive messages
      16. -
        -           
        -    connection1.start();
        -           
        -        
        - -
      17. create a consumer
      18. -
        -           
        -    MessageConsumer consumer = session1.createConsumer(queue);
        -            
        -        
        - -
      19. Receive and acknowledge all of the sent messages, notice that they will be out of order, this is - because they were initially round robined to both nodes then when the server failed were reloaded into the - live server.
      20. -
        -           
        -    TextMessage message0 = null;
        -    for (int i = 0; i < numMessages * 2; i++)
        -    {
        -       message0 = (TextMessage)consumer.receive(5000);
        -       System.out.println("Got message: " + message0.getText());
        -    }
        -    message0.acknowledge();
        -           
        -        
        - - - - -
      21. And finally (no pun intended), always remember to close your JMS resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
      22. - -
        -           
        -    finally
        -    {
        -       if (connection != null)
        -       {
        -       connection.close();
        -       }
        -
        -       if (initialContext != null)
        -       {
        -       initialContext.close();
        -       }
        -       if (connection1 != null)
        -       {
        -       connection1.close();
        -       }
        -
        -       if (initialContext1 != null)
        -       {
        -       initialContext1.close();
        -       }
        -    }
        -           
        -        
        - -
      diff --git a/examples/jms/colocated-failover/pom.xml b/examples/jms/colocated-failover/pom.xml index a501d385b2..121b2969d3 100644 --- a/examples/jms/colocated-failover/pom.xml +++ b/examples/jms/colocated-failover/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -42,64 +43,60 @@ under the License. ${project.version} - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - - - example - - - - org.apache.activemq - artemis-maven-plugin - - - create0 - - create - - - ${basedir}/target/server0 - ${basedir}/target/classes/activemq/server0 - - - - create1 - - create - - - ${basedir}/target/server1 - ${basedir}/target/classes/activemq/server1 - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.ColocatedFailoverExample - - ${basedir}/target/server0 - ${basedir}/target/server1 - - - - - - - org.apache.activemq.examples.jms - colocated-failover - ${project.version} - - - - - - - + + + + org.apache.activemq + artemis-maven-plugin + + + create0 + + create + + + ${basedir}/target/server0 + ${basedir}/target/classes/activemq/server0 + + + + create1 + + create + + + ${basedir}/target/server1 + ${basedir}/target/classes/activemq/server1 + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.ColocatedFailoverExample + + ${basedir}/target/server0 + ${basedir}/target/server1 + + + + + + + org.apache.activemq.examples.jms + colocated-failover + ${project.version} + + + + + diff --git a/examples/jms/colocated-failover/readme.html b/examples/jms/colocated-failover/readme.html index 9e787d5518..dceae4ff22 100644 --- a/examples/jms/colocated-failover/readme.html +++ b/examples/jms/colocated-failover/readme.html @@ -26,6 +26,7 @@ under the License.

      JMS Colocated Failover Shared Store Example

      +
      To run the example, simply type mvn verify from this directory. This example will always spawn and stop multiple servers.

      This example demonstrates how you can colocate live and backup servers in the same VM. We do this by creating an HA Policy that is colocated. colocated means that backup servers can be created and maintained by live servers on behalf @@ -51,143 +52,5 @@ under the License.

      notice that we have used a template to set some sensible defaults but overridden the backup strategy so back ups are full servers

      -

      Example step-by-step

      -

      To run the example, simply type mvn verify -Pexample from this directory

      - -
        -
      1. Get an initial context for looking up JNDI for both servers
      2. -
        -           
        -    initialContext1 = getContext(1);
        -    initialContext = getContext(0);
        -   
        -        
        - -
      3. Look up the JMS resources from JNDI
      4. -
        -           
        -    Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue");
        -    ConnectionFactory connectionFactory = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
        -    ConnectionFactory connectionFactory1 = (ConnectionFactory)initialContext1.lookup("/ConnectionFactory");
        -           
        -        
        - -
      5. Create a JMS Connections
      6. -
        -           
        -    connection = connectionFactory.createConnection();
        -    connection1 = connectionFactory1.createConnection();
        -           
        -        
        - -
      7. Create a *non-transacted* JMS Session with client acknowledgement
      8. -
        -           
        -    Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        -    Session session1 = connection1.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        -           
        -        
        - -
      9. Create a JMS MessageProducer
      10. -
        -           
        -    MessageProducer producer = session.createProducer(queue);
        -    MessageProducer producer1 = session1.createProducer(queue);
        -           
        -        
        - -
      11. Send some messages to both servers
      12. -
        -          
        -    for (int i = 0; i < numMessages; i++)
        -    {
        -      TextMessage message = session.createTextMessage("This is text message " + i);
        -      producer.send(message);
        -      System.out.println("Sent message: " + message.getText());
        -      message = session1.createTextMessage("This is another text message " + i);
        -      producer1.send(message);
        -      System.out.println("Sent message: " + message.getText());
        -    }
        -          
        -        
        - -
      13. Crash server #0, the live server
      14. -
        -          
        -    killServer(0);
        -          
        -        
        - -
      15. start the connection ready to receive messages
      16. -
        -           
        -    connection1.start();
        -           
        -        
        - -
      17. create a consumer
      18. -
        -           
        -    MessageConsumer consumer = session1.createConsumer(queue);
        -            
        -        
        - -
      19. Receive and acknowledge all of the sent messages, the backup server that is colocated with server 1 - will have become live and is now handling messages for server 0.
      20. -
        -           
        -    TextMessage message0 = null;
        -    for (int i = 0; i < numMessages; i++)
        -    {
        -       message0 = (TextMessage)consumer.receive(5000);
        -       System.out.println("Got message: " + message0.getText());
        -    }
        -    message0.acknowledge();
        -           
        -        
        - -
      21. Receive and acknowledge the rest of the sent messages from server 1.
      22. -
        -           
        -   for (int i = 0; i < numMessages; i++)
        -   {
        -   message0 = (TextMessage)consumer1.receive(5000);
        -   System.out.println("Got message: " + message0.getText());
        -   }
        -   message0.acknowledge();
        -           
        -        
        - - - -
      23. And finally (no pun intended), always remember to close your JMS resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
      24. - -
        -           
        -    finally
        -    {
        -       if (connection != null)
        -       {
        -       connection.close();
        -       }
        -
        -       if (initialContext != null)
        -       {
        -       initialContext.close();
        -       }
        -       if (connection1 != null)
        -       {
        -       connection1.close();
        -       }
        -
        -       if (initialContext1 != null)
        -       {
        -       initialContext1.close();
        -       }
        -    }
        -           
        -        
        - -
      diff --git a/examples/jms/consumer-rate-limit/pom.xml b/examples/jms/consumer-rate-limit/pom.xml index b6442a009a..32bce35c1c 100644 --- a/examples/jms/consumer-rate-limit/pom.xml +++ b/examples/jms/consumer-rate-limit/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-consumer-rate-limit-example + consumer-rate-limit jar ActiveMQ Artemis JMS Consumer Rate Limit Example @@ -37,71 +38,81 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.ConsumerRateLimitExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-consumer-rate-limit-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.ConsumerRateLimitExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + consumer-rate-limit + ${project.version} + + + + + diff --git a/examples/jms/consumer-rate-limit/readme.html b/examples/jms/consumer-rate-limit/readme.html index 6492b37a4a..8b7c9e2c35 100644 --- a/examples/jms/consumer-rate-limit/readme.html +++ b/examples/jms/consumer-rate-limit/readme.html @@ -26,6 +26,7 @@ under the License.

      JMS Message Consumer Rate Limiting

      +
      To run the example, simply type mvn verify from this directory, 
      or mvn -PnoServer verify if you want to start and create the server manually.

      With ActiveMQ Artemis you can specify a maximum consume rate at which a JMS MessageConsumer will consume messages. This can be specified when creating or configuring the connection factory. See jndi.properties.

      @@ -42,131 +43,5 @@ connectionFactory.ConnectionFactory=tcp://localhost:61616?consumerMaxRate=10

      We then simply consume as many messages as we can in 10 seconds and note how many messages are actually consumed.

      We note that the number of messages consumed per second never exceeds the specified value of 10 messages per second.

      -

      To run the example, simply type mvn verify -Pexample from this directory

      - -
        -
      1. Create an initial context to perform the JNDI lookup.
      2. -
        -           initialContext = getContext(0);
        -        
        - -
      3. Perfom a lookup on the queue
      4. -
        -           Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue");
        -        
        - -
      5. Perform a lookup on the Connection Factory
      6. -
        -           ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
        -        
        - -
      7. Create a JMS Connection
      8. -
        -           connection = cf.createConnection();
        -        
        - -
      9. Create a JMS Session
      10. -
        -           Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        -        
        - -
      11. Create a JMS MessageProducer
      12. -
        -          MessageProducer producer = session.createProducer(queue);
        -        
        - -
      13. Create a JMS MessageConsumer
      14. -
        -           MessageConsumer consumer = session.createConsumer(queue);
        -        
        - -
      15. Start the connection
      16. - -
        -           
        -     connection.start();
        -           
        -        
        - - -
      17. Send a bunch of messages
      18. -
        -           
        -     final int numMessages = 150;
        -
        -     for (int i = 0; i < numMessages; i++)
        -     {
        -        TextMessage message = session.createTextMessage("This is text message: " + i);
        -
        -        producer.send(message);
        -     }
        -           
        -        
        - -
      19. Consume as many messages as we can in 10 seconds
      20. - -
        -           
        -   final long duration = 10000;
        -
        -   int i = 0;
        -
        -   long start = System.currentTimeMillis();
        -
        -   while (System.currentTimeMillis() - start <= duration)
        -   {
        -      TextMessage message = (TextMessage)consumer.receive(2000);
        -
        -      if (message == null)
        -      {
        -         return false;
        -      }
        -
        -      i++;
        -   }
        -
        -   long end = System.currentTimeMillis();
        -
        -   double rate = 1000 * (double)i / (end - start);
        -
        -   System.out.println("We consumed " + i + " messages in " + (end - start) + " milliseconds");
        -
        -   System.out.println("Actual consume rate was " + rate + " messages per second");
        -           
        -        
        - -
      21. This should produce output something like:
      22. - -
        -           
        -    [java] Sent messages
        -    [java] Will now try and consume as many as we can in 10 seconds ...
        -    [java] We consumed 100 messages in 10001 milliseconds
        -    [java] Actual consume rate was 9.99900009999 messages per second
        -
        -           
        -        
        - -
      23. Be sure to close our resources!
      24. - -
        -           
        -           finally
        -           {
        -              if (initialContext != null)
        -              {
        -                initialContext.close();
        -              }
        -
        -              if (connection != null)
        -              {
        -                 connection.close();
        -              }
        -           }
        -        
        - - - -
      diff --git a/examples/jms/dead-letter/pom.xml b/examples/jms/dead-letter/pom.xml index 94f2c4c40e..5a39fd403f 100644 --- a/examples/jms/dead-letter/pom.xml +++ b/examples/jms/dead-letter/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-dead-letter-example + dead-letter jar ActiveMQ Artemis JMS Dead Letter Example @@ -37,71 +38,82 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.DeadLetterExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-dead-letter-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${basedir}/target/classes/activemq/server0 + ${noServer} + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.DeadLetterExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + dead-letter + ${project.version} + + + + + diff --git a/examples/jms/dead-letter/readme.html b/examples/jms/dead-letter/readme.html index 36985e29c7..deb836dca2 100644 --- a/examples/jms/dead-letter/readme.html +++ b/examples/jms/dead-letter/readme.html @@ -26,9 +26,10 @@ under the License.

      Dead Letter Example

      +
      To run the example, simply type mvn verify from this directory, 
      or mvn -PnoServer verify if you want to start and create the server manually.

      This example shows you how to define and deal with dead letter messages.

      -

      Messages can be delivered unsuccessfully (e.g. if the transacted session used to consume them is rolled back). +

      Messages can be delivered unsuccessfully (e.g. if the transacted session used to consume them is rolled back). Such a message goes back to the JMS destination ready to be redelivered. However, this means it is possible for a message to be delivered again and again without any success and remain in the destination, clogging the system.

      To prevent this, messaging systems define dead letter messages: after a specified unsuccessful delivery attempts, the message is removed from the destination @@ -47,12 +48,12 @@ under the License. <max-delivery-attempts>3</max-delivery-attempts> </address-setting> - +

      This configuration will moved dead letter messages from exampleQueue to the deadLetterQueue.

      ActiveMQ Artemis allows to specify either a Queue by prefixing the dead-letter-address with jms.queue. or a Topic by prefixing with jms.topic..
      In this example, we will use a Queue to hold the dead letter messages.

      -

      The maximum attempts of delivery is 3. Once this figure is reached, a message is considered a dead letter message and is moved to +

      The maximum attempts of delivery is 3. Once this figure is reached, a message is considered a dead letter message and is moved to the deadLetterQueue.

      Since we want to consume messages from this deadLetterQueue, we also need to add a JNDI binding to perform a lookup. This is configured in activemq-jms.xml

      @@ -61,166 +62,5 @@ under the License. <entry name="/queue/deadLetterQueue"/> </queue> -

      -

      Example step-by-step

      -

      To run the example, simply type mvn verify -Pexample from this directory

      -
        -
      1. First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the client-jndi.properties file in the directory ../common/config
      2. -
        -           InitialContext initialContext = getContext();
        -        
        - -
      3. We look up the JMS queue object from JNDI
      4. -
        -           Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");
        -        
        - -
      5. We look up the JMS connection factory object from JNDI
      6. -
        -           ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
        -        
        - -
      7. We create a JMS connection
      8. -
        -           connection = cf.createConnection();
        -        
        - -
      9. We create a JMS transacted session -
        -           Session session = connection.createSession(true, 0);
        -        
        - -
      10. We create a JMS message producer on the session. This will be used to send the messages
      11. -
        -          MessageProducer messageProducer = session.createProducer(topic);
        -       
        - -
      12. We create a text messages
      13. -
        -            TextMessage message = session.createTextMessage("this is a text message");
        -        
        - -
      14. We send the message to the queue
      15. -
        -            producer.send(message);
        -        
        - -
      16. We commit the session to effectively send the message to the queue
      17. -
        -            session.commit();
        -        
        - -

        We will now consume the message from the queue 3 times and roll back the session every time

        - -
      18. We create a JMS message consumer on the queue
      19. -
        -            MessageConsumer messageConsumer = session.createConsumer(queue);
        -        
        - -
      20. We start the connection. In order for delivery to occur on any consumers or subscribers on a connection, the connection must be started
      21. -
        -           connection.start();
        -        
        - -
      22. We receive the message a 1st time
      23. -
        -            TextMessage messageReceived = (TextMessage)messageConsumer.receive(5000);
        -            System.out.println("1st delivery from " + queue.getQueueName() + ": " + messageReceived.getText());            
        -        
        - -
      24. We roll back the session. The message we received is undelivered and goes back to the queue
      25. -
        -            session.rollback();
        -        
        - -
      26. We receive a message and roll back the session a 2nd time -
        -            messageReceived = (TextMessage)messageConsumer.receive(5000);
        -            System.out.println("2nd delivery from " + queue.getQueueName() + ": " + messageReceived.getText());
        -            session.rollback();
        -        
        - -
      27. We do it againt a 3rd time -
        -           messageReceived = (TextMessage)messageConsumer.receive(5000);
        -           System.out.println("3rd delivery from " + queue.getQueueName() + ": " + messageReceived.getText());
        -           session.rollback();
        -       
        - -

        Since the queue was configured to move messages to the deadLetterQueue after 3 unsuccessful delivery attempts, - the message won't be in the queue anymore

        - -
      28. We try to receive a message from the queue for a 4th. Since there is none, the call will timeout after 5000ms and messageReceived will be null -
        -           messageReceived = (TextMessage)messageConsumer.receive(5000);
        -           System.out.println("4th delivery from " + queue.getQueueName() + ": " + messageReceived);
        -        
        - -

        We have configured ActiveMQ Artemis to send any dead letter messages to the deadLetterQueue. - We will now consume messages from this queue and receives the dead letter messages.

        - -
      29. We look up the JMS dead letter queue object from JNDI
      30. -
        -           Queue deadLetterQueue = (Queue)initialContext.lookup("/queue/deadLetterQueue");
        -        
        - -
      31. We create a JMS message consumer on the dead letter queue
      32. -
        -            MessageConsumer deadLetterConsumer = session.createConsumer(expiryQueue);
        -        
        - -
      33. We consume a message from the dead letter queue:
      34. -
        -            messageReceived = (TextMessage)deadLetterConsumer.receive(5000);
        -        
        - -
      35. The message consumed from the dead letter queue has the same content than the message which was sent to the queue -
        -            System.out.println("Received message from " + deadLetterQueue.getQueueName() + ": " + messageReceived.getText());
        -        
        - -

        JMS does not specify the notion of dead letter destinations and messages. From JMS point of view, the message received from the dead letter queue - is a different message than the message removed from the queue after the unsuccessful delivery attempts: - the messages have the same content (properties and body) but their JMS headers differ.
        - ActiveMQ Artemis defines additional properties for messages received from a dead letter destination

        - -
      36. The message's destination is the dead letter queue
      37. -
        -            System.out.println("Destination of the message: " + ((Queue)messageReceived.getJMSDestination()).getQueueName());
        -        
        - -
      38. The origin destination is stored in the _AMQ_ORIG_ADDRESS property -
        -            System.out.println("*Origin destination* of the message: " + messageReceived.getStringProperty("_AMQ_ORIG_ADDRESS"));
        -        
        - -
      39. We do not forget to commit the session to acknowledge that we have received the message from the dead letter queue
      40. -
        -            session.commit();
        -        
        - -

        -
      41. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
      42. - -
        -           finally
        -           {
        -              if (initialContext != null)
        -              {
        -                initialContext.close();
        -              }
        -              if (connection != null)
        -              {
        -                 connection.close();
        -              }
        -           }
        -        
        -
      - -

      More information

      - - diff --git a/examples/jms/delayed-redelivery/pom.xml b/examples/jms/delayed-redelivery/pom.xml index 764efdad41..2fd509025a 100644 --- a/examples/jms/delayed-redelivery/pom.xml +++ b/examples/jms/delayed-redelivery/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-delayed-redelivery-example + delayed-redelivery jar ActiveMQ Artemis JMS Delayed Redelivery Example @@ -37,71 +38,82 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.DelayedRedeliveryExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-delayed-redelivery-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${basedir}/target/classes/activemq/server0 + ${noServer} + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.DelayedRedeliveryExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + delayed-redelivery + ${project.version} + + + + + diff --git a/examples/jms/delayed-redelivery/readme.html b/examples/jms/delayed-redelivery/readme.html index 8613c024f1..09ecb38fd2 100644 --- a/examples/jms/delayed-redelivery/readme.html +++ b/examples/jms/delayed-redelivery/readme.html @@ -26,7 +26,8 @@ under the License.

      Delayed Redelivery Example

      - +
      To run the example, simply type mvn verify from this directory, 
      or mvn -PnoServer verify if you want to start and create the server manually.
      +

      This example demonstrates how ActiveMQ Artemis can be configured to provide a delayed redelivery in the case where a message needs to be redelivered.

      Delaying redelivery can often be useful in the case that clients regularly fail or roll-back. Without a delayed @@ -46,142 +47,10 @@ under the License.

      We then consume a message in a transacted session, and rollback, and note that the message is not redelivered until after 5 seconds.

      -         <address-setting match="jms.queue.exampleQueue">           
      +         <address-setting match="jms.queue.exampleQueue">
                   <redelivery-delay>5000</redelivery-delay>
                </address-setting>
                
      -     
      -

      To run the example, simply type mvn verify -Pexample from this directory

      -
        -
      1. Create an initial context to perform the JNDI lookup.
      2. -
        -           initialContext = getContext(0);
        -        
        - -
      3. Perform a lookup on the queue
      4. -
        -           Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue");
        -        
        - -
      5. Perform a lookup on the Connection Factory
      6. -
        -           ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
        -        
        - -
      7. Create a JMS Connection
      8. -
        -           connection = cf.createConnection();
        -        
        - -
      9. Create a transacted JMS Session -
        -           Session session = connection.createSession(true, 0);
        -        
        - -
      10. Create a JMS Message Producer
      11. -
        -          MessageProducer producer = session.createProducer(queue);
        -       
        - -
      12. Create a Text Message
      13. -
        -            TextMessage message = session.createTextMessage("this is a text message");
        -        
        - -
      14. Send the Message
      15. -
        -            producer.send(message);
        -        
        - -
      16. We commit the session to effectively send the message to the queue
      17. -
        -            session.commit();
        -        
        - -
      18. We create a JMS message consumer on the queue
      19. -
        -            MessageConsumer messageConsumer = session.createConsumer(queue);
        -        
        - -
      20. We start the connection. In order for delivery to occur on any consumers or subscribers on a connection, the connection must be started
      21. -
        -           connection.start();
        -        
        - -
      22. We receive the message...
      23. -
        -            TextMessage messageReceived = (TextMessage)messageConsumer.receive(5000);
        -            System.out.println("1st delivery from " + queue.getQueueName() + ": " + messageReceived.getText());            
        -        
        - -
      24. ...but we roll back the session. the message returns to the queue, but only after a - 5 second delay
      25. -
        -            session.rollback();
        -        
        - -
      26. We try to receive the message but it's being delayed
      27. -
        -            
        -         messageReceived = (TextMessage)messageConsumer.receive(3000);
        -         
        -         if (messageReceived != null)
        -         {
        -            return false;
        -         }
        -         
        -         System.out.println("Redelivery has been delayed so received message is " + messageReceived);
        -            
        -            
        -        
        - -
      28. We try and receive the message again, this time we should get it
      29. -
        -                        
        -         messageReceived = (TextMessage)messageConsumer.receive(3000);
        -         
        -         System.out.println("2nd delivery from " + queue.getQueueName() + ": " + messageReceived.getText());
        -           
        -       
        - -
      30. We rollback the session again to cause another redelivery, and we time how long this one takes -
        -           
        -         long start = System.currentTimeMillis();
        -         
        -         session.rollback();
        -                         
        -         messageReceived = (TextMessage)messageConsumer.receive(8000);
        -         
        -         long end = System.currentTimeMillis();
        -         
        -         System.out.println("3nd delivery from " + queue.getQueueName() + ": " + messageReceived.getText() +
        -                            " after " + (end - start) + " milliseconds.");           
        -           
        -        
        - -
      31. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
      32. - -
        -           finally
        -           {
        -              if (initialContext != null)
        -              {
        -                initialContext.close();
        -              }
        -              if (connection != null)
        -              {
        -                 connection.close();
        -              }
        -           }
        -        
        -
      - -

      More information

      - - - + diff --git a/examples/jms/divert/pom.xml b/examples/jms/divert/pom.xml index 46dfbc6177..4c912b25cb 100644 --- a/examples/jms/divert/pom.xml +++ b/examples/jms/divert/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -26,8 +27,7 @@ under the License. jms-examples 1.0.1-SNAPSHOT - - artemis-jms-divert-example + divert jar ActiveMQ Artemis JMS Divert Example @@ -42,114 +42,127 @@ under the License. ${project.version} - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create0 - - create - - - ${basedir}/target/server0 - ${basedir}/target/classes/activemq/server0 - - - - create1 - - create - - - ${basedir}/target/server1 - ${basedir}/target/classes/activemq/server1 - - - - start0 - - cli - - - true - tcp://localhost:61616 - - run - - server0 - - - - start1 - - cli - - - true - ${basedir}/target/server1 - tcp://localhost:61617 - - run - - server1 - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.DivertExample - - - - stop0 - - cli - - - ${basedir}/target/server0 - - stop - - - - - stop1 - - cli - - - ${basedir}/target/server1 - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-divert-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create0 + + create + + + ${noServer} + org.apache.activemq.examples.jms:divert:${project.version} + ${basedir}/target/server0 + ${basedir}/target/classes/activemq/server0 + + + + create1 + + create + + + ${noServer} + org.apache.activemq.examples.jms:divert:${project.version} + ${basedir}/target/server1 + ${basedir}/target/classes/activemq/server1 + + + + start0 + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + server0 + + + + start1 + + cli + + + ${noServer} + true + ${basedir}/target/server1 + tcp://localhost:61617 + + run + + server1 + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.DivertExample + + + + stop0 + + cli + + + ${noServer} + ${basedir}/target/server0 + + stop + + + + + stop1 + + cli + + + ${noServer} + ${basedir}/target/server1 + + stop + + + + + + + org.apache.activemq.examples.jms + divert + ${project.version} + + + + + diff --git a/examples/jms/divert/readme.html b/examples/jms/divert/readme.html index 6a5707f40e..62067d6819 100644 --- a/examples/jms/divert/readme.html +++ b/examples/jms/divert/readme.html @@ -26,6 +26,7 @@ under the License.

      Divert Example

      +
      To run the example, simply type mvn verify from this directory, 
      or mvn -PnoServer verify if you want to start and create the server manually.

      ActiveMQ Artemis diverts allow messages to be transparently "diverted" from one address to another with just some simple configuration defined on the server side.

      @@ -114,325 +115,5 @@ under the License. </bridges> - -

      To run the example, simply type mvn verify -Pexample from this directory

      - -
        -
      1. Create an initial context to perform the JNDI lookup on the London server
      2. -
        -           
        -     initialContext0 = getContext(0);
        -           
        -        
        - -
      3. Look-up the queue orderQueue on the London server - this is the queue any orders are sent to
      4. -
        -           
        -     Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");
        -           
        -        
        - -
      5. Look-up the topic priceUpdates on the London server- this is the topic that any price updates are sent to
      6. -
        -           
        -     Topic priceUpdates = (Topic)initialContextLondon.lookup("/topic/priceUpdates");
        -           
        -        
        - -
      7. Look-up the spy topic on the London server- this is what we will use to snoop on any orders
      8. -
        -           
        -     Topic spyTopic = (Topic)initialContextLondon.lookup("/topic/spyTopic");
        -           
        -        
        - -
      9. Create an initial context to perform the JNDI lookup on the New York server.
      10. -
        -           
        -     initialContextNewYork = getContext(1);
        -           
        -        
        - -
      11. Look-up the topic newYorkPriceUpdates on the New York server - any price updates sent to priceUpdates on the London server will - be diverted to the queue priceForward on the London server, and a bridge will consume from that queue and forward - them to the address newYorkPriceUpdates on the New York server where they will be distributed to the topic subscribers on - the New York server. -
      12. -
        -          
        -     Topic newYorkPriceUpdates = (Topic)initialContextNewYork.lookup("/topic/newYorkPriceUpdates");
        -          
        -       
        - -
      13. Perform a lookup on the Connection Factory on the London server
      14. -
        -           
        -    ConnectionFactory cfLondon = (ConnectionFactory)initialContextLondon.lookup("/ConnectionFactory");
        -           
        -        
        - -
      15. Perform a lookup on the Connection Factory on the New York server.
      16. -
        -           
        -    ConnectionFactory cfNewYork = (ConnectionFactory)initialContextNewYork.lookup("/ConnectionFactory");
        -           
        -        
        - -
      17. Create a JMS Connection on the London server
      18. -
        -           
        -    connectionLondon = cfLondon.createConnection();
        -           
        -        
        - -
      19. Create a JMS Connection on the New York server
      20. -
        -           
        -    connectionNewYork = cfNewYork.createConnection();
        -           
        -        
        - -
      21. Create a JMS Session on the London server.
      22. -
        -           
        -    Session sessionLondon = connectionLondon.createSession(false, Session.AUTO_ACKNOWLEDGE);
        -           
        -        
        - -
      23. Create a JMS Session on the New York server.
      24. -
        -           
        -    Session sessionNewYork = connectionNewYork.createSession(false, Session.AUTO_ACKNOWLEDGE);
        -           
        -        
        - -
      25. Create a JMS MessageProducer orderProducer that sends to the queue orderQueue on the London server.
      26. -
        -           
        -    MessageProducer orderProducer = sessionLondon.createProducer(orderQueue);
        -           /code>
        -        
        - -
      27. Create a JMS MessageProducer priceProducer that sends to the topic priceUpdates on the London server.
      28. -
        -           
        -    MessageProducer priceProducer = sessionLondon.createProducer(priceUpdates);
        -           /code>
        -        
        - -
      29. Create a JMS subscriber which subscribes to the spyTopic on the London server
      30. -
        -           
        -    MessageConsumer spySubscriberA = sessionLondon.createConsumer(spyTopic);
        -           
        -        
        - -
      31. Create another JMS subscriber which also subscribes to the spyTopic on the London server
      32. -
        -           
        -    MessageConsumer spySubscriberB = sessionLondon.createConsumer(spyTopic);
        -           
        -        
        - -
      33. Create a JMS MessageConsumer which consumes orders from the order queue on the London server
      34. -
        -           
        -    MessageConsumer orderConsumer = sessionLondon.createConsumer(orderQueue);
        -           
        -        
        - -
      35. Create a JMS subscriber which subscribes to the priceUpdates topic on the London server
      36. -
        -           
        -    MessageConsumer priceUpdatesSubscriberLondon = sessionLondon.createConsumer(priceUpdates);
        -           
        -        
        - -
      37. Create a JMS subscriber which subscribes to the newYorkPriceUpdates topic on the New York server
      38. -
        -           
        -    MessageConsumer newYorkPriceUpdatesSubscriberA = sessionNewYork.createConsumer(newYorkPriceUpdates);
        -           
        -        
        - -
      39. Create another JMS subscriber which also subscribes to the newYorkPriceUpdates topic on the New York server
      40. -
        -           
        -    MessageConsumer newYorkPriceUpdatesSubscriberB = sessionNewYork.createConsumer(newYorkPriceUpdates);
        -           
        -        
        - -
      41. Start the connections
      42. -
        -           
        -    connectionLondon.start();
        -
        -    connectionNewYork.start();
        -           
        -        
        - -
      43. Create an order message
      44. -
        -           
        -    TextMessage orderMessage = sessionLondon.createTextMessage("This is an order");
        -           
        -        
        - -
      45. Send the order message to the order queue on the London server
      46. -
        -           
        -    orderProducer.send(orderMessage);
        -
        -    System.out.println("Sent message: " + orderMessage.getText());
        -           
        -        
        - -
      47. The order message is consumed by the orderConsumer on the London server
      48. -
        -           
        -    TextMessage receivedOrder = (TextMessage)orderConsumer.receive(5000);
        -
        -    System.out.println("Received order: " + receivedOrder.getText());
        -           
        -        
        - -
      49. A copy of the order is also received by the spyTopic subscribers on the London server
      50. -
        -           
        -    TextMessage spiedOrder1 = (TextMessage)spySubscriberA.receive(5000);
        -
        -    System.out.println("Snooped on order: " + spiedOrder1.getText());
        -
        -    TextMessage spiedOrder2 = (TextMessage)spySubscriberB.receive(5000);
        -
        -    System.out.println("Snooped on order: " + spiedOrder2.getText());
        -           
        -        
        - -
      51. Create and send a price update message, destined for London
      52. -
        -           
        -    TextMessage priceUpdateMessageLondon = sessionLondon.createTextMessage("This is a price update for London");
        -
        -    priceUpdateMessageLondon.setStringProperty("office", "London");
        -
        -    priceProducer.send(priceUpdateMessageLondon);
        -           
        -        
        - -
      53. The price update *should* be received by the local subscriber since we only divert messages - where office = New York
      54. -
        -           
        -    TextMessage receivedUpdate = (TextMessage)priceUpdatesSubscriberLondon.receive(2000);
        -
        -    System.out.println("Received price update locally: " + receivedUpdate.getText());
        -           
        -        
        - -
      55. The price update *should not* be received in New York
      56. -
        -           
        -    TextMessage priceUpdate1 = (TextMessage)newYorkPriceUpdatesSubscriberA.receive(1000);
        -
        -    if (priceUpdate1 != null)
        -    {
        -       return false;
        -    }
        -
        -    System.out.println("Did not received price update in New York, look it's: " + priceUpdate1);
        -
        -    TextMessage priceUpdate2 = (TextMessage)newYorkPriceUpdatesSubscriberB.receive(1000);
        -
        -    if (priceUpdate2 != null)
        -    {
        -       return false;
        -    }
        -
        -    System.out.println("Did not received price update in New York, look it's: " + priceUpdate2);
        -           
        -        
        - -
      57. Create a price update message, destined for New York
      58. -
        -           
        -    TextMessage priceUpdateMessageNewYork = sessionLondon.createTextMessage("This is a price update for New York");
        -
        -    priceUpdateMessageNewYork.setStringProperty("office", "New York");
        -           
        -        
        - -
      59. Send the price update message to the priceUpdates topic on the London server
      60. -
        -           
        -   priceProducer.send(priceUpdateMessageNewYork);
        -           
        -        
        - -
      61. The price update *should not* be received by the local subscriber to the priceUpdates topic - since it has been *exclusively* diverted to the priceForward queue, because it has a header saying - it is destined for the New York office
      62. -
        -           
        -   Message message = priceUpdatesSubscriberLondon.receive(1000);
        -
        -   if (message != null)
        -   {
        -      return false;
        -   }
        -
        -   System.out.println("Didn't receive local price update, look, it's: " + message);
        -           
        -        
        - -
      63. The remote subscribers on server 1 *should* receive a copy of the price update since - it has been diverted to a local priceForward queue which has a bridge consuming from it and which - forwards it to the same address on server 1. - We notice how the forwarded messages have had a special header added by our custom transformer that - we told the divert to use
      64. -
        -           
        -   priceUpdate1 = (TextMessage)newYorkPriceUpdatesSubscriberA.receive(5000);
        -
        -   System.out.println("Received forwarded price update on server 1: " + priceUpdate1.getText());
        -   System.out.println("Time of forward: " + priceUpdate1.getLongProperty("time_of_forward"));
        -
        -   priceUpdate2 = (TextMessage)newYorkPriceUpdatesSubscriberB.receive(5000);
        -
        -   System.out.println("Received forwarded price update on server 2: " + priceUpdate2.getText());
        -   System.out.println("Time of forward: " + priceUpdate2.getLongProperty("time_of_forward"));
        -           
        -        
        - - -
      65. And finally, always remember to close your resources after use, in a finally block.
      66. - -
        -           
        -   finally
        -   {
        -      if (initialContextLondon != null)
        -      {
        -         initialContextLondon.close();
        -      }
        -      if (initialContextNewYork != null)
        -      {
        -         initialContextNewYork.close();
        -      }
        -      if (connectionLondon != null)
        -      {
        -         connectionLondon.close();
        -      }
        -      if (connectionNewYork != null)
        -      {
        -         connectionNewYork.close();
        -      }
        -   }
        -           
        -        
        - - - -
      diff --git a/examples/jms/divert/src/main/java/org/apache/activemq/artemis/jms/example/DivertExample.java b/examples/jms/divert/src/main/java/org/apache/activemq/artemis/jms/example/DivertExample.java index 9cbaaa6268..3d74c55368 100644 --- a/examples/jms/divert/src/main/java/org/apache/activemq/artemis/jms/example/DivertExample.java +++ b/examples/jms/divert/src/main/java/org/apache/activemq/artemis/jms/example/DivertExample.java @@ -25,8 +25,9 @@ import javax.jms.Queue; import javax.jms.Session; import javax.jms.TextMessage; import javax.jms.Topic; -import javax.naming.InitialContext; -import java.util.Hashtable; + +import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; /** * This examples demonstrates the use of ActiveMQ Artemis "Diverts" to transparently divert or copy messages @@ -41,37 +42,17 @@ public class DivertExample Connection connectionLondon = null; Connection connectionNewYork = null; - - InitialContext initialContextLondon = null; - - InitialContext initialContextNewYork = null; try { - // Step 1. Create an initial context to perform the JNDI lookup on the London server - Hashtable properties = new Hashtable(); - properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); - properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61616"); - properties.put("queue.queue/orders", "orders"); - properties.put("topic.topic/priceUpdates", "priceUpdates"); - properties.put("topic.topic/spyTopic", "spyTopic"); - initialContextLondon = new InitialContext(properties); - // Step 2. Look-up the queue orderQueue on the London server - this is the queue any orders are sent to - Queue orderQueue = (Queue)initialContextLondon.lookup("queue/orders"); + Queue orderQueue = ActiveMQJMSClient.createQueue("orders"); // Step 3. Look-up the topic priceUpdates on the London server- this is the topic that any price updates are // sent to - Topic priceUpdates = (Topic)initialContextLondon.lookup("topic/priceUpdates"); + Topic priceUpdates = ActiveMQJMSClient.createTopic("priceUpdates"); // Step 4. Look-up the spy topic on the London server- this is what we will use to snoop on any orders - Topic spyTopic = (Topic)initialContextLondon.lookup("topic/spyTopic"); - - // Step 6. Create an initial context to perform the JNDI lookup on the New York server - properties = new Hashtable(); - properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); - properties.put("connectionFactory.ConnectionFactory2", "tcp://localhost:61617"); - properties.put("topic.topic/newYorkPriceUpdates", "newYorkPriceUpdates"); - initialContextNewYork = new InitialContext(properties); + Topic spyTopic = ActiveMQJMSClient.createTopic("spyTopic"); // Step 7. Look-up the topic newYorkPriceUpdates on the New York server - any price updates sent to // priceUpdates on the London server will @@ -80,13 +61,13 @@ public class DivertExample // them to the address newYorkPriceUpdates on the New York server where they will be distributed to the topic // subscribers on // the New York server - Topic newYorkPriceUpdates = (Topic)initialContextNewYork.lookup("topic/newYorkPriceUpdates"); + Topic newYorkPriceUpdates = ActiveMQJMSClient.createTopic("newYorkPriceUpdates"); // Step 8. Perform a lookup on the Connection Factory on the London server - ConnectionFactory cfLondon = (ConnectionFactory)initialContextLondon.lookup("ConnectionFactory"); + ConnectionFactory cfLondon = new ActiveMQConnectionFactory("tcp://localhost:61616"); // Step 9. Perform a lookup on the Connection Factory on the New York server - ConnectionFactory cfNewYork = (ConnectionFactory)initialContextNewYork.lookup("ConnectionFactory2"); + ConnectionFactory cfNewYork = new ActiveMQConnectionFactory("tcp://localhost:61617"); // Step 10. Create a JMS Connection on the London server connectionLondon = cfLondon.createConnection(); @@ -226,15 +207,6 @@ public class DivertExample } finally { - // Step 12. Be sure to close our resources! - if (initialContextLondon != null) - { - initialContextLondon.close(); - } - if (initialContextNewYork != null) - { - initialContextNewYork.close(); - } if (connectionLondon != null) { connectionLondon.close(); diff --git a/examples/jms/durable-subscription/pom.xml b/examples/jms/durable-subscription/pom.xml index 9571cd8c8e..a87bf2805d 100644 --- a/examples/jms/durable-subscription/pom.xml +++ b/examples/jms/durable-subscription/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-durable-subscription-example + durable-subscription jar ActiveMQ Artemis JMS Durable Subscription Example @@ -37,71 +38,82 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.DurableSubscriptionExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-durable-subscription-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + ${basedir}/target/classes/activemq/server0 + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.DurableSubscriptionExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + durable-subscription + ${project.version} + + + + + diff --git a/examples/jms/durable-subscription/readme.html b/examples/jms/durable-subscription/readme.html index 4379baac43..def30b7d4e 100644 --- a/examples/jms/durable-subscription/readme.html +++ b/examples/jms/durable-subscription/readme.html @@ -27,133 +27,13 @@ under the License.

      JMS Durable Subscription Example

      +
      To run the example, simply type mvn verify from this directory, 
      or mvn -PnoServer verify if you want to start and create the server manually.

      This example demonstrates how to use a durable subscription with ActiveMQ Artemis.

      Durable subscriptions are a standard part of JMS, please consult the JMS 1.1 specification for full details.

      Unlike non durable subscriptions, the key function of durable subscriptions is that the messages contained in them persist longer than the lifetime of the subscriber - i.e. they will accumulate messages sent to the topic even - if the subscriber is not currently connected. They will also survive server restarts. Note that for the messages to + if the subscriber is not currently connected. They will also survive server restarts. Note that for the messages to be persisted, the messages sent to them must be marked as persistent messages.

      -

      Example step-by-step

      -

      To run the example, simply type mvn verify -Pexample from this directory

      - -
        -
      1. First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the client-jndi.properties file in the directory ../common/config
      2. -
        -           initialContext = getContext();
        -        
        - -
      3. We look-up the JMS topic object from JNDI
      4. -
        -           Topic topic = (Topic) initialContext.lookup("/topic/exampleTopic");
        -        
        - -
      5. We look-up the JMS connection factory object from JNDI
      6. -
        -           ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
        -        
        - -
      7. We create a JMS connection
      8. -
        -           connection = cf.createConnection();
        -        
        - -
      9. We set the client-id on the connection. This must be the first operation performed on the connection object. - The combination of client-id and durable subscription name uniquely identifies the durable subscription. Maybe different durable subscritions can have the same name if they belong to different client-id values
      10. -
        -           connection.setClientID("durable-client");
        -        
        - -
      11. We start the connection. In order for delivery to occur on any consumers or subscribers on a connection, the connection must be started
      12. -
        -           connection.start();
        -        
        - -
      13. We create a JMS session. The session is created as non transacted and will auto acknowledge messages.
      14. -
        -           Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        -        
        - -
      15. We create a JMS message producer on the session. This will be used to send the messages.
      16. -
        -	   MessageProducer messageProducer = session.createProducer(topic);
        -        
        - -
      17. We create the durable subscriber on the topic, specifying it's name. Since this is the first time the subscriber is created and a subscription with that name and for this client-id does not already exist, then the underlying durable subscription will be created, and a subscriber will be created and returned for that subscription.
      18. -
        -           TopicSubscriber subscriber = session.createDurableSubscriber(topic, "subscriber-1");
        -        
        - -
      19. We create a JMS text message, message 1, that we are going to send. Note that it must be a persistent message in order to survive server restart.
      20. -
        -           TextMessage message1 = session.createTextMessage("This is a text message 1");
        -        
        - -
      21. We send message 1 to the topic
      22. -
        -           messageProducer.send(message1);
        -        
        - -
      23. The message arrives in the subscription, and we consume the message from the subscription.
      24. -
        -           TextMessage messageReceived = (TextMessage)subscriber.receive();
        -        
        - -
      25. We create and send another text message, message 2, to the same topic
      26. -
        -           TextMessage message2 = session.createTextMessage("This is a text message 2");
        -              
        -           messageProducer.send(message2);
        -        
        - -
      27. Now we close the subscriber. Since the subscription is durable it will continue to survive even though there is no subscriber attached to it. At this point you could even stop and restart the server and the subscription would survive!
      28. - -
        -           subscriber.close();
        -        
        - -
      29. We now create another durable subscriber, with the same name and same client-id on the same topic. Since the durable subscrition already exists, it will simply return a new subscriber consuming from the same durable subscription instance as before
      30. - -
         
        -           subscriber = session.createDurableSubscriber(topic, "subscriber-1");
        -        
        - -
      31. We consume message 2 which was sent before the first subscriber was closed.
      32. - -
        -           messageReceived = (TextMessage)subscriber.receive();
        -        
        - -
      33. We close the second subscriber.
      34. - -
        -           subscriber.close();
        -        
        - -
      35. Now we delete the underlying durable subscription. This will delete any remaining unacknowledged messages in the subscription and a new subscriber will not be able to access them
      36. - -
        -           session.unsubscribe("subscriber-1");
        -        
        - -
      37. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
      38. - -
        -           finally
        -           {
        -              if (initialContext != null)
        -              {
        -                initialContext.close();
        -              }
        -              if (connection != null)
        -              {
        -                 connection.close();
        -              }
        -           }
        -        
        - - - -
      diff --git a/examples/jms/embedded-simple/pom.xml b/examples/jms/embedded-simple/pom.xml index a1dae0930b..8b190330e3 100644 --- a/examples/jms/embedded-simple/pom.xml +++ b/examples/jms/embedded-simple/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-embedded-simple-example + embedded-simple jar ActiveMQ Artemis JMS Simple Embedded Example @@ -47,41 +48,37 @@ under the License. ${project.version} - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - - - example - - - - org.apache.activemq - artemis-maven-plugin - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.EmbeddedExample - - - - - - org.apache.activemq.examples.jms - artemis-jms-embedded-simple-example - ${project.version} - - - - - - - + + + + org.apache.activemq + artemis-maven-plugin + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.EmbeddedExample + + + + + + org.apache.activemq.examples.jms + embedded-simple + ${project.version} + + + + + diff --git a/examples/jms/embedded/pom.xml b/examples/jms/embedded/pom.xml index 8d81f45394..75d876ca3a 100644 --- a/examples/jms/embedded/pom.xml +++ b/examples/jms/embedded/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-embedded-example + embedded jar ActiveMQ Artemis JMS Embedded Example @@ -47,41 +48,37 @@ under the License. ${project.version} - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - - - example - - - - org.apache.activemq - artemis-maven-plugin - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.EmbeddedExample - - - - - - org.apache.activemq.examples.jms - artemis-jms-embedded-example - ${project.version} - - - - - - - + + + + org.apache.activemq + artemis-maven-plugin + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.EmbeddedExample + + + + + + org.apache.activemq.examples.jms + embedded + ${project.version} + + + + + diff --git a/examples/jms/embedded/readme.html b/examples/jms/embedded/readme.html index b64ea4c7fd..b1bdd0f9c6 100644 --- a/examples/jms/embedded/readme.html +++ b/examples/jms/embedded/readme.html @@ -26,78 +26,13 @@ under the License.

      Embedded JMS Server Example

      - +
      To run the example, simply type mvn verify from this directory
      +

      This examples shows how to setup and run an embedded JMS server using ActiveMQ Artemis.

      ActiveMQ Artemis was designed using POJOs (Plain Old Java Objects) which means embedding ActiveMQ Artemis in your own application is as simple as instantiating a few objects.

      -

      This example does not use any configuration files. The server is configured using POJOs and can be easily ported to any dependency injection framework.
      +

      This example does not use any configuration files. The server is configured using POJOs and can be easily ported to any dependency injection framework.
      We will setup and run a full-fledged JMS server which binds its JMS resources to JNDI and can be accessed by remote clients.

      - -

      Example step-by-step

      -

      To run the example, simply type mvn verify -Pexample from this directory

      -
        -
      1. Create ActiveMQ Artemis core configuration, and set the properties accordingly
      2. -
        -            Configuration configuration = new ConfigurationImpl();
        -            configuration.setPersistenceEnabled(false);
        -            configuration.setSecurityEnabled(false);
        -            configuration.getAcceptorConfigurations().add(new TransportConfiguration(NettyAcceptorFactory.class.getName()));
        -            Configuration configuration = new ConfigurationImpl();
        - -
      3. Create the ActiveMQ Artemis core server
      4. -
        -            ActiveMQServer activemqServer = ActiveMQ Artemis.newActiveMQServer(configuration);
        -         
        - -
      5. Create the JMS configuration
      6. -
        -            JMSConfiguration jmsConfig = new JMSConfigurationImpl();
        -         
        - -
      7. Configure the JMS ConnectionFactory
      8. -
        -            TransportConfiguration connectorConfig = new TransportConfiguration(NettyConnectorFactory.class.getName());
        -            ConnectionFactoryConfiguration cfConfig = new ConnectionFactoryConfigurationImpl("cf", connectorConfig, "/cf");
        -            jmsConfig.getConnectionFactoryConfigurations().add(cfConfig);
        -         
        - -
      9. Configure the JMS Queue
      10. -
        -            QueueConfiguration queueConfig = new QueueConfigurationImpl("queue1", null, false, "/queue/queue1");
        -            jmsConfig.getQueueConfigurations().add(queueConfig);
        -         
        - -
      11. Start the JMS Server using the ActiveMQ Artemis core server and the JMS configuration
      12. -
        -            JMSServerManager jmsServer = new JMSServerManagerImpl(activemqServer, jmsConfig);
        -            jmsServer.start();
        -         
        - -

        At this point the JMS server is started and any JMS clients can look up JMS resources from JNDI to send/receive - messages from the server. To keep the example simple, we will send and receive a JMS message from the same JVM - used to run the JMS server.

        - -
      13. Lookup JMS resources defined in the configuration
      14. -
        -            ConnectionFactory cf = (ConnectionFactory)context.lookup("/cf");
        -            Queue queue = (Queue)context.lookup("/queue/queue1");
        -         
        - -
      15. Send and receive a message using JMS API
      16. -

        See the Queue Example for detailed steps to send and receive a JMS message

        - -

        Finally, we stop the JMS server and its associated resources.

        - -
      17. Stop the JMS server
      18. -
        -            jmsServer.stop();
        -         
        - -
      19. Stop the JNDI server
      20. -
        -            naming.stop();
        -         
        -
      diff --git a/examples/jms/expiry/pom.xml b/examples/jms/expiry/pom.xml index 9c539996c4..44c48e407f 100644 --- a/examples/jms/expiry/pom.xml +++ b/examples/jms/expiry/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-expiry-example + expiry jar ActiveMQ Artemis JMS Expiry Example @@ -37,71 +38,82 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.ExpiryExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-expiry-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + ${basedir}/target/classes/activemq/server0 + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.ExpiryExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + expiry + ${project.version} + + + + + diff --git a/examples/jms/expiry/readme.html b/examples/jms/expiry/readme.html index acbbe4bbea..65cb534c07 100644 --- a/examples/jms/expiry/readme.html +++ b/examples/jms/expiry/readme.html @@ -26,6 +26,7 @@ under the License.

      JMS Expiration Example

      +
      To run the example, simply type mvn verify from this directory, 
      or mvn -PnoServer verify if you want to start and create the server manually.

      This example shows you how to configure ActiveMQ Artemis so messages are expipired after a certain time.

      Messages can be retained in the messaging system for a limited period of time before being removed. @@ -44,7 +45,7 @@ under the License. <expiry-address>jms.queue.expiryQueue</expiry-address> </address-setting> - +

      This configuration will moved expired messages from the exampleQueue to the expiryQueue

      ActiveMQ Artemis allows to specify either a Queue by prefixing the expiry-address with jms.queue. or a Topic by prefixing with jms.topic..
      @@ -56,151 +57,5 @@ under the License. <entry name="/queue/expiryQueue"/> </queue>
      -

      -

      Example step-by-step

      -

      To run the example, simply type mvn verify -Pexample from this directory

      -
        -
      1. First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the client-jndi.properties file in the directory ../common/config
      2. -
        -           InitialContext initialContext = getContext();
        -        
        - -
      3. We look up the JMS queue object from JNDI
      4. -
        -           Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");
        -        
        - -
      5. We look up the JMS connection factory object from JNDI
      6. -
        -           ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
        -        
        - -
      7. We create a JMS connection
      8. -
        -           connection = cf.createConnection();
        -        
        - -
      9. We create a JMS session. The session is created as non transacted and will auto acknowledge messages
      10. -
        -           Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        -        
        - -
      11. We create a JMS message producer on the session. This will be used to send the messages
      12. -
        -          MessageProducer messageProducer = session.createProducer(topic);
        -       
        - -
      13. Messages sent by this producer will be retained for 1s (1000ms) before expiration
      14. -
        -           producer.setTimeToLive(1000);
        -       
        - -
      15. We create a text messages
      16. -
        -            TextMessage message = session.createTextMessage("this is a text message");
        -        
        - -
      17. We send the message to the queue
      18. -
        -            producer.send(message);
        -        
        - -
      19. We sleep a little bit to let the message expire
      20. -
        -            Thread.sleep(5000);
        -        
        - -

        We will now try to consume the message from the queue but it won't be there since it has expired

        - -
      21. We create a JMS message consumer on the queue
      22. -
        -            MessageConsumer messageConsumer = session.createConsumer(queue);
        -        
        - -
      23. We start the connection. In order for delivery to occur on any consumers or subscribers on a connection, the connection must be started
      24. -
        -           connection.start();
        -        
        - -
      25. We try to receive a message from the queue. Since there is none, the call will timeout after 5000ms and messageReceived will be null -
        -           TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
        -           System.out.println("Received message from " + queue.getQueueName() + ": " + messageReceived);
        -        
        - -

        However, we have configured ActiveMQ Artemis to send any expired messages to the expiryQueue. - We will now consume messages from this expiry queue and receives the expired message.

        - -
      26. We look up the JMS expiry queue object from JNDI
      27. -
        -           Queue expiryQueue = (Queue)initialContext.lookup("/queue/expiryQueue");
        -        
        - -
      28. We create a JMS message consumer on the expiry queue
      29. -
        -            MessageConsumer expiryConsumer = session.createConsumer(expiryQueue);
        -        
        - -
      30. We consume a message from the expiry queue:
      31. -
        -            messageReceived = (TextMessage)expiryConsumer.receive(5000);
        -        
        - -
      32. The message consumed from the expiry queue has the same content than the message which was sent to the queue -
        -            System.out.println("Received message from " + expiryQueue.getQueueName() + ": " + messageReceived.getText());
        -        
        - -

        JMS does not specify the notion of expiry queue. From JMS point of view, the message received from the expiry queue - is a different message than the message expired from the queue: the two messages have the same content (properties and body) but - their JMS headers differ.
        - ActiveMQ Artemis defines additional properties to correlate the message received from the expiry queue with the - message expired from the queue

        - -
      33. The expired message's destination is the expiry queue
      34. -
        -            System.out.println("Destination of the expired message: " + ((Queue)messageReceived.getJMSDestination()).getQueueName());
        -        
        - -
      35. The expired message has its own expiration time (its time to live in the expiry queue)
      36. -
        -            System.out.println("Expiration time of the expired message (relative to the expiry queue): " + messageReceived.getJMSExpiration());
        -        
        - -

        As we have not defined a time-to-live for the expiry queue, messages sent to the expiry queue will be kept forever (their JMS Expiration value is 0)

        - -
      37. The origin destination is stored in the _HORNETQ_ORIG_DESTINATION property -
        -            System.out.println("*Origin destination* of the expired message: " + messageReceived.getStringProperty("_HORNETQ_ORIG_DESTINATION"));
        -        
        - -
      38. The actual expiration time (when the message was expired from the queue) is stored in the _HORNETQ_ACTUAL_EXPIRY property -
        -            System.out.println("*Actual expiration time* of the expired message: " + messageReceived.getLongProperty("_HORNETQ_ACTUAL_EXPIRY"));
        -        
        - -

        -
      39. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
      40. - -
        -           finally
        -           {
        -              if (initialContext != null)
        -              {
        -                initialContext.close();
        -              }
        -              if (connection != null)
        -              {
        -                 connection.close();
        -              }
        -           }
        -        
        -
      - -

      More information

      - - diff --git a/examples/jms/ha-policy-autobackup/pom.xml b/examples/jms/ha-policy-autobackup/pom.xml index cace530748..9e33342a74 100644 --- a/examples/jms/ha-policy-autobackup/pom.xml +++ b/examples/jms/ha-policy-autobackup/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -42,65 +43,61 @@ under the License. ${project.version} - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - - - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - ${basedir}/target/server0 - ${basedir}/target/classes/activemq/server0 - - - - create2 - - create - - - ${basedir}/target/server1 - ${basedir}/target/classes/activemq/server1 - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.HAPolicyAutoBackupExample - - ${basedir}/target/server0 - ${basedir}/target/server1 - - - - - - - org.apache.activemq.examples.jms - ha-policy-autobackup - ${project.version} - - - - - - - + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${basedir}/target/server0 + ${basedir}/target/classes/activemq/server0 + + + + create2 + + create + + + ${basedir}/target/server1 + ${basedir}/target/classes/activemq/server1 + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.HAPolicyAutoBackupExample + + ${basedir}/target/server0 + ${basedir}/target/server1 + + + + + + + org.apache.activemq.examples.jms + ha-policy-autobackup + ${project.version} + + + + + diff --git a/examples/jms/ha-policy-autobackup/src/main/java/org/apache/activemq/artemis/jms/example/HAPolicyAutoBackupExample.java b/examples/jms/ha-policy-autobackup/src/main/java/org/apache/activemq/artemis/jms/example/HAPolicyAutoBackupExample.java index d56175068e..93d3d53f5b 100644 --- a/examples/jms/ha-policy-autobackup/src/main/java/org/apache/activemq/artemis/jms/example/HAPolicyAutoBackupExample.java +++ b/examples/jms/ha-policy-autobackup/src/main/java/org/apache/activemq/artemis/jms/example/HAPolicyAutoBackupExample.java @@ -16,12 +16,6 @@ */ package org.apache.activemq.artemis.jms.example; -import org.apache.activemq.artemis.api.core.TransportConfiguration; -import org.apache.activemq.artemis.api.core.client.ClusterTopologyListener; -import org.apache.activemq.artemis.api.core.client.TopologyMember; -import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; -import org.apache.activemq.artemis.util.ServerUtil; - import javax.jms.Connection; import javax.jms.ConnectionFactory; import javax.jms.MessageConsumer; @@ -29,13 +23,18 @@ import javax.jms.MessageProducer; import javax.jms.Queue; import javax.jms.Session; import javax.jms.TextMessage; -import javax.naming.InitialContext; import java.util.ArrayList; -import java.util.Hashtable; import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import org.apache.activemq.artemis.api.core.TransportConfiguration; +import org.apache.activemq.artemis.api.core.client.ClusterTopologyListener; +import org.apache.activemq.artemis.api.core.client.TopologyMember; +import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; +import org.apache.activemq.artemis.util.ServerUtil; + /** * A simple example that demonstrates server side load-balancing of messages between the queue instances on different * nodes of the cluster. @@ -52,33 +51,17 @@ public class HAPolicyAutoBackupExample Connection connection1 = null; - InitialContext ic0 = null; - - InitialContext ic1 = null; - try { server0 = ServerUtil.startServer(args[0], HAPolicyAutoBackupExample.class.getSimpleName() + "0", 0, 5000); server1 = ServerUtil.startServer(args[1], HAPolicyAutoBackupExample.class.getSimpleName() + "1", 1, 5000); - // Step 1. Get an initial context for looking up JNDI from server 0 and 1 - Hashtable properties = new Hashtable(); - properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); - properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61616?ha=true&retryInterval=1000&retryIntervalMultiplier=1.0&reconnectAttempts=-1"); - properties.put("queue.queue/exampleQueue", "exampleQueue"); - ic0 = new InitialContext(properties); - - properties = new Hashtable(); - properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); - properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61617?ha=true&retryInterval=1000&retryIntervalMultiplier=1.0&reconnectAttempts=-1"); - ic1 = new InitialContext(properties); - // Step 2. Look-up the JMS Queue object from JNDI - Queue queue = (Queue) ic0.lookup("queue/exampleQueue"); + Queue queue = ActiveMQJMSClient.createQueue("exampleQueue"); - // Step 3. Look-up a JMS Connection Factory object from JNDI on server 0 and 1 - ConnectionFactory cf0 = (ConnectionFactory) ic0.lookup("ConnectionFactory"); - ConnectionFactory cf1 = (ConnectionFactory) ic1.lookup("ConnectionFactory"); + // Step 3. new connection factories towards server 0 and 1 + ConnectionFactory cf0 = new ActiveMQConnectionFactory("tcp://localhost:61616?ha=true&retryInterval=1000&retryIntervalMultiplier=1.0&reconnectAttempts=-1"); + ConnectionFactory cf1 = new ActiveMQConnectionFactory("tcp://localhost:61617?ha=true&retryInterval=1000&retryIntervalMultiplier=1.0&reconnectAttempts=-1"); // Step 6. We create JMS Connections to server 0 and 1 connection0 = cf0.createConnection(); @@ -129,7 +112,7 @@ public class HAPolicyAutoBackupExample // Step 15.now kill server1, messages will be scaled down to server0 ServerUtil.killServer(server1); - Thread.sleep(40000); + Thread.sleep(5000); // Step 16. we now receive the messages that were on server1 but were scaled down to server0 for (int i = 0; i < numMessages / 2; i++) diff --git a/examples/jms/http-transport/pom.xml b/examples/jms/http-transport/pom.xml index 0d9c91d2c5..6e2914b59e 100644 --- a/examples/jms/http-transport/pom.xml +++ b/examples/jms/http-transport/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-http-transport-example + http-transport jar ActiveMQ Artemis JMS Http Transport Example @@ -37,71 +38,82 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:8080?http-enabled=true - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.HttpTransportExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-http-transport-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + ${basedir}/target/classes/activemq/server0 + + + + start + + cli + + + ${noServer} + true + tcp://localhost:8080?http-enabled=true + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.HttpTransportExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + http-transport + ${project.version} + + + + + diff --git a/examples/jms/http-transport/readme.html b/examples/jms/http-transport/readme.html index 9cc3f8c540..a0f0005d6b 100644 --- a/examples/jms/http-transport/readme.html +++ b/examples/jms/http-transport/readme.html @@ -27,14 +27,17 @@ under the License.

      JMS HTTP Example

      + +
      To run the example, simply type mvn verify from this directory, 
      or mvn -PnoServer verify if you want to start and create the server manually.
      +

      This example shows you how to configure ActiveMQ Artemis to use the HTTP protocol as its transport layer.

      - +

      ActiveMQ Artemis supports a variety of network protocols to be its underlying transport without any specific code change.

      - +

      This example is taken from the queue example without any code change. By changing the configuration file, one can get ActiveMQ Artemis working with HTTP transport.

      All you need to do is open the server0/broker.xml and enable HTTP like the following

      - - + +
             
             <connector name="netty-connector">tcp://localhost:8080?httpEnabled=true</connector>
      @@ -44,84 +47,6 @@ under the License.
             <acceptor name="netty-acceptor">tcp://localhost:8080 </acceptor>
             
             
      - -

      Example step-by-step

      -

      To run the example, simply type mvn verify -Pexample from this directory

      -
        -
      1. First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the client-jndi.properties file in the directory ../common/config
      2. -
        -           InitialContext initialContext = getContext();
        -        
        - -
      3. We look-up the JMS queue object from JNDI
      4. -
        -           Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");
        -        
        - -
      5. We look-up the JMS connection factory object from JNDI
      6. -
        -           ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
        -        
        - -
      7. We create a JMS connection
      8. -
        -           connection = cf.createConnection();
        -        
        - -
      9. We create a JMS session. The session is created as non transacted and will auto acknowledge messages.
      10. -
        -           Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        -        
        - -
      11. We create a JMS message producer on the session. This will be used to send the messages.
      12. -
        -          MessageProducer messageProducer = session.createProducer(topic);
        -       
        - -
      13. We create a JMS text message that we are going to send.
      14. -
        -           TextMessage message = session.createTextMessage("This is a text message");
        -        
        - -
      15. We send message to the queue
      16. -
        -           messageProducer.send(message);
        -        
        - -
      17. We create a JMS Message Consumer to receive the message.
      18. -
        -           MessageConsumer messageConsumer = session.createConsumer(queue);
        -        
        - -
      19. We start the connection. In order for delivery to occur on any consumers or subscribers on a connection, the connection must be started
      20. -
        -           connection.start();
        -        
        - -
      21. The message arrives at the consumer. In this case we use a timeout of 5000 milliseconds but we could use a blocking 'receive()'
      22. -
        -           TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
        -        
        - -
      23. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
      24. - -
        -           finally
        -           {
        -              if (initialContext != null)
        -              {
        -                initialContext.close();
        -              }
        -              if (connection != null)
        -              {
        -                 connection.close();
        -              }
        -           }
        -        
        - - - -
      diff --git a/examples/jms/http-transport/src/main/java/org/apache/activemq/artemis/jms/example/HttpTransportExample.java b/examples/jms/http-transport/src/main/java/org/apache/activemq/artemis/jms/example/HttpTransportExample.java index cd2e17529d..9ae1cbacea 100644 --- a/examples/jms/http-transport/src/main/java/org/apache/activemq/artemis/jms/example/HttpTransportExample.java +++ b/examples/jms/http-transport/src/main/java/org/apache/activemq/artemis/jms/example/HttpTransportExample.java @@ -25,6 +25,9 @@ import javax.jms.Session; import javax.jms.TextMessage; import javax.naming.InitialContext; +import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; + /** * A simple JMS Queue example that uses HTTP protocol. */ @@ -33,17 +36,13 @@ public class HttpTransportExample public static void main(final String[] args) throws Exception { Connection connection = null; - InitialContext initialContext = null; try { - // Step 1. Create an initial context to perform the JNDI lookup. - initialContext = new InitialContext(); - // Step 2. Perfom a lookup on the queue - Queue queue = (Queue)initialContext.lookup("queue/exampleQueue"); + Queue queue = ActiveMQJMSClient.createQueue("exampleQueue"); // Step 3. Perform a lookup on the Connection Factory - ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("ConnectionFactory"); + ConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:8080?http-enabled=true"); // Step 4.Create a JMS Connection connection = cf.createConnection(); @@ -75,15 +74,9 @@ public class HttpTransportExample System.out.println("Received message: " + messageReceived.getText()); - initialContext.close(); } finally { - // Step 12. Be sure to close our JMS resources! - if (initialContext != null) - { - initialContext.close(); - } if (connection != null) { connection.close(); diff --git a/examples/jms/http-transport/src/main/resources/activemq/server0/broker.xml b/examples/jms/http-transport/src/main/resources/activemq/server0/broker.xml index ea39ccd01f..d1a4d2a70c 100644 --- a/examples/jms/http-transport/src/main/resources/activemq/server0/broker.xml +++ b/examples/jms/http-transport/src/main/resources/activemq/server0/broker.xml @@ -29,13 +29,13 @@ under the License. - ${data.dir:../data}/bindings + ./data/bindings - ${data.dir:../data}/journal + ./data/journal - ${data.dir:../data}/largemessages + ./data/largemessages - ${data.dir:../data}/paging + ./data/paging diff --git a/examples/jms/http-transport/src/main/resources/jndi.properties b/examples/jms/http-transport/src/main/resources/jndi.properties deleted file mode 100644 index 15dae0bb59..0000000000 --- a/examples/jms/http-transport/src/main/resources/jndi.properties +++ /dev/null @@ -1,20 +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. - -java.naming.factory.initial=org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory -connectionFactory.ConnectionFactory=tcp://localhost:8080?http-enabled=true -queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/instantiate-connection-factory/pom.xml b/examples/jms/instantiate-connection-factory/pom.xml index 774b2b2a98..1f4d2e6ba4 100644 --- a/examples/jms/instantiate-connection-factory/pom.xml +++ b/examples/jms/instantiate-connection-factory/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-instantiate-connection-factory-example + instantiate-connection-factory jar ActiveMQ Artemis JMS Instantiate Connection Factory Example @@ -35,83 +36,85 @@ under the License. ${project.basedir}/../../.. + - - org.apache.activemq - artemis-core-client - ${project.version} - org.apache.activemq artemis-jms-client ${project.version} - - org.apache.geronimo.specs - geronimo-jms_2.0_spec - - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.InstantiateConnectionFactoryExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-instantiate-connection-factory-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.InstantiateConnectionFactoryExample + + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + instantiate-connection-factory + ${project.version} + + + + + diff --git a/examples/jms/instantiate-connection-factory/readme.html b/examples/jms/instantiate-connection-factory/readme.html index ff4e17ac0b..fa062eab71 100644 --- a/examples/jms/instantiate-connection-factory/readme.html +++ b/examples/jms/instantiate-connection-factory/readme.html @@ -26,7 +26,9 @@ under the License.

      JMS Instantiate Connection Factory Example

      - + +
      To run the example, simply type mvn verify from this directory, 
      or mvn -PnoServer verify if you want to start and create the server manually.
      +

      Usually, JMS Objects such as ConnectionFactories, Queue and Topic instances are looked up from JNDI before being used by the client code. This objects are called "administered objects" in JMS specification terminology.

      @@ -43,95 +45,5 @@ under the License. are that it wishes to connect to, or for specifying live-backup pairs of servers for failover.

      For more information on instantiating ConnectionFactories directly please consult the user manual and javadoc.

      - -

      Example step-by-step

      -

      To run the example, simply type mvn verify -Pexample from this directory

      - -
        -
      1. Instead of looking it up from JNDI we directly instantiate the JMS Queue object. We - pass in the name of the JMS Queue in the constructor. The actual JMS Queue must already be deployed on - the server.
      2. -
        -           
        -     Queue queue = new ActiveMQQueue("exampleQueue");
        -        
        - -
      3. Instantiate the TransportConfiguration object. The TransportConfiguration instance encapsulates - the connection details of the server we're connecting to. In this case we're using Netty as a transport, and - we're specifying to connect on port 61617.
      4. -
        -           
        -     Map connectionParams = new HashMap();
        -
        -     connectionParams.put(PORT_PROP_NAME, 61617);
        -
        -     TransportConfiguration transportConfiguration = new TransportConfiguration(NettyConnectorFactory.class.getName(),
        -                                                                                connectionParams);
        -           
        -           
        -        
        - -
      5. Directly instantiate the JMS ConnectionFactory object using that TransportConfiguration.
      6. -
        -           
        -     ConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(transportConfiguration);
        -           
        -        
        - -
      7. We create a JMS connection
      8. -
        -           connection = cf.createConnection();
        -        
        - -
      9. We create a JMS session. The session is created as non transacted and will auto acknowledge messages.
      10. -
        -           Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        -        
        - -
      11. We create a JMS message producer on the session. This will be used to send the messages.
      12. -
        -          MessageProducer messageProducer = session.createProducer(topic);
        -       
        - -
      13. We create a JMS text message that we are going to send.
      14. -
        -           TextMessage message = session.createTextMessage("This is a text message");
        -        
        - -
      15. We send message to the queue
      16. -
        -           messageProducer.send(message);
        -        
        - -
      17. We create a JMS Message Consumer to receive the message.
      18. -
        -           MessageConsumer messageConsumer = session.createConsumer(queue);
        -        
        - -
      19. We start the connection. In order for delivery to occur on any consumers or subscribers on a connection, the connection must be started
      20. -
        -           connection.start();
        -        
        - -
      21. The message arrives at the consumer. In this case we use a timeout of 5000 milliseconds but we could use a blocking 'receive()'
      22. -
        -           TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
        -        
        - -
      23. And finally, always remember to close your resources after use, in a finally block.
      24. - -
        -           finally
        -           {
        -              if (connection != null)
        -              {
        -                 connection.close();
        -              }
        -           }
        -        
        - - - -
      - + diff --git a/examples/jms/instantiate-connection-factory/src/main/java/org/apache/activemq/artemis/jms/example/InstantiateConnectionFactoryExample.java b/examples/jms/instantiate-connection-factory/src/main/java/org/apache/activemq/artemis/jms/example/InstantiateConnectionFactoryExample.java index b0acce48b3..9b1e46ea20 100644 --- a/examples/jms/instantiate-connection-factory/src/main/java/org/apache/activemq/artemis/jms/example/InstantiateConnectionFactoryExample.java +++ b/examples/jms/instantiate-connection-factory/src/main/java/org/apache/activemq/artemis/jms/example/InstantiateConnectionFactoryExample.java @@ -23,14 +23,9 @@ import javax.jms.MessageProducer; import javax.jms.Queue; import javax.jms.Session; import javax.jms.TextMessage; -import java.util.HashMap; -import java.util.Map; -import org.apache.activemq.artemis.api.core.TransportConfiguration; 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.core.remoting.impl.netty.TransportConstants; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; /** * @@ -49,17 +44,8 @@ public class InstantiateConnectionFactoryExample // Step 1. Directly instantiate the JMS Queue object. Queue queue = ActiveMQJMSClient.createQueue("exampleQueue"); - // Step 2. Instantiate the TransportConfiguration object which contains the knowledge of what transport to use, - // The server port etc. - - Map connectionParams = new HashMap(); - connectionParams.put(TransportConstants.PORT_PROP_NAME, 61616); - - TransportConfiguration transportConfiguration = new TransportConfiguration(NettyConnectorFactory.class.getName(), - connectionParams); - - // Step 3 Directly instantiate the JMS ConnectionFactory object using that TransportConfiguration - ConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, transportConfiguration); + // Starting with Artemis 1.0.1 you can just use the URI to instantiate the object directly + ConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616"); // Step 4.Create a JMS Connection connection = cf.createConnection(); diff --git a/examples/jms/interceptor/pom.xml b/examples/jms/interceptor/pom.xml index 530a7b9e0a..63ab338dc2 100644 --- a/examples/jms/interceptor/pom.xml +++ b/examples/jms/interceptor/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-interceptor-example + interceptor jar ActiveMQ Artemis JMS Interceptor Example @@ -41,72 +42,79 @@ under the License. artemis-jms-client ${project.version} - - org.apache.geronimo.specs - geronimo-jms_2.0_spec - - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.InterceptorExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-interceptor-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + org.apache.activemq.examples.jms:interceptor:${project.version} + ${noServer} + ${basedir}/target/classes/activemq/server0 + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.InterceptorExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + interceptor + ${project.version} + + + + + diff --git a/examples/jms/interceptor/readme.html b/examples/jms/interceptor/readme.html index a680c12040..e4d3601dde 100644 --- a/examples/jms/interceptor/readme.html +++ b/examples/jms/interceptor/readme.html @@ -27,6 +27,9 @@ under the License.

      JMS Interceptor Example

      +
      To run the example, simply type mvn verify from this directory, 
      or mvn -PnoServer verify if you want to start and create the server manually.
      + +

      This example shows you how to implement and configure a simple incoming, server-side interceptor with ActiveMQ Artemis.

      ActiveMQ Artemis allows an application to use an interceptor to hook into the messaging system. All that needs to do is to implement the @@ -59,113 +62,6 @@ under the License.

      With our interceptor we always return true from the intercept method. If we were to return false that signifies that no more interceptors are to run or the target is not to be called. Return false to abort processing of the packet.

      - -

      Example step-by-step

      -

      To run the example, simply type mvn verify -Pexample from this directory

      - -
        -
      1. First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the client-jndi.properties file in the directory ../common/config
      2. -
        -           InitialContext initialContext = getContext(0);
        -        
        - -
      3. We look-up the JMS queue object from JNDI
      4. -
        -           Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");
        -        
        - -
      5. We look-up the JMS connection factory object from JNDI
      6. -
        -           ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
        -        
        - -
      7. We create a JMS connection
      8. -
        -           connection = cf.createConnection();
        -        
        - -
      9. We create a JMS session. The session is created as non transacted and will auto acknowledge messages.
      10. -
        -           Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        -        
        - -
      11. We create a JMS message producer on the session. This will be used to send the messages.
      12. -
        -          MessageProducer messageProducer = session.createProducer(topic);
        -       
        - -
      13. We create a JMS text message that we are going to send.
      14. -
        -           TextMessage message = session.createTextMessage("This is a text message");
        -        
        - -
      15. We send message to the queue
      16. -
        -           messageProducer.send(message);
        -        
        - -
      17. We create a JMS Message Consumer to receive the message.
      18. -
        -           MessageConsumer messageConsumer = session.createConsumer(queue);
        -        
        - -
      19. We start the connection. In order for delivery to occur on any consumers or subscribers on a connection, the connection must be started
      20. -
        -           connection.start();
        -        
        - -
      21. The message arrives at the consumer. In this case we use a timeout of 5000 milliseconds but we could use a blocking 'receive()'
      22. -
        -           TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
        -        
        - -
      23. We print out the message and the new property that has been added by the interceptor
      24. -
        -           System.out.println("Received message [" + messageReceived.getText() + "] with String property: " + messageReceived.getStringProperty("newproperty"));
        -        
        - -
      25. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
      26. - -
        -           
        -           finally
        -           {
        -              if (initialContext != null)
        -              {
        -                initialContext.close();
        -              }
        -              if (connection != null)
        -              {
        -                 connection.close();
        -              }
        -           }
        -           
        -        
        -
      -
        -
      1. The SimpleInterceptor:
      2. -
        -           
        -           public class SimpleInterceptor implements Interceptor
        -           {
        -              public boolean intercept(Packet packet, RemotingConnection connection) throws ActiveMQException
        -              {
        -                 System.out.println("SimpleInterceptor gets called!");
        -                 System.out.println("Packet: " + packet.getClass().getName());
        -                 System.out.println("RemotingConnection: " + connection.getRemoteAddress());
        -
        -                 if (packet instanceof SessionSendMessage)
        -                 {
        -                    SessionSendMessage realPacket = (SessionSendMessage)packet;
        -                    Message msg = realPacket.getServerMessage();
        -                    msg.putStringProperty(new SimpleString("newproperty"), new SimpleString("Hello from interceptor!"));
        -                 }
        -                 return true;
        -              }
        -           }
        -           
        -        
        -
      diff --git a/examples/jms/jms-auto-closeable/pom.xml b/examples/jms/jms-auto-closeable/pom.xml index 17376ab6a8..3066fa59cb 100644 --- a/examples/jms/jms-auto-closeable/pom.xml +++ b/examples/jms/jms-auto-closeable/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-auto-closeable-example + auto-closeable jar ActiveMQ Artemis JMS Auto Closable Example @@ -37,71 +38,78 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.JMSAutoCloseableExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-auto-closeable-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.JMSAutoCloseableExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + auto-closeable + ${project.version} + + + + + diff --git a/examples/jms/jms-auto-closeable/readme.html b/examples/jms/jms-auto-closeable/readme.html index 48cc246247..7e7155371e 100644 --- a/examples/jms/jms-auto-closeable/readme.html +++ b/examples/jms/jms-auto-closeable/readme.html @@ -27,11 +27,12 @@ under the License.

      JMS Auto Closable Example

      +
      To run the example, simply type mvn verify from this directory, 
      or mvn -PnoServer verify if you want to start and create the server manually.
      +

      This example shows you how JMS resources, such as connections, sessions and consumers, in JMS 2 can be automatically closed on error.

      In this instance we auto close a connection after a subsequent call to a JMS producer send fails

      Example step-by-step

      -

      To run the example, simply type mvn verify -Pexample from this directory

      1. First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the client-jndi.properties file in the directory ../common/config
      2. diff --git a/examples/jms/jms-auto-closeable/src/main/java/org/apache/activemq/artemis/jms/example/JMSAutoCloseableExample.java b/examples/jms/jms-auto-closeable/src/main/java/org/apache/activemq/artemis/jms/example/JMSAutoCloseableExample.java index 555e8ff1d1..a4f13e8827 100644 --- a/examples/jms/jms-auto-closeable/src/main/java/org/apache/activemq/artemis/jms/example/JMSAutoCloseableExample.java +++ b/examples/jms/jms-auto-closeable/src/main/java/org/apache/activemq/artemis/jms/example/JMSAutoCloseableExample.java @@ -16,9 +16,12 @@ */ package org.apache.activemq.artemis.jms.example; -import javax.jms.*; -import javax.naming.InitialContext; -import java.lang.Exception; +import javax.jms.JMSContext; +import javax.jms.JMSProducer; +import javax.jms.Queue; + +import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; /** * A simple JMS example that shows how AutoCloseable is used by JMS 2 resources. @@ -27,45 +30,24 @@ public class JMSAutoCloseableExample { public static void main(final String[] args) throws Exception { - InitialContext initialContext = null; + // Step 2. Perfom a lookup on the queue + Queue queue = ActiveMQJMSClient.createQueue("exampleQueue"); + + // Step 4.Create a JMS Context using the try-with-resources statement try + ( + // Even though ConnectionFactory is not closeable it would be nice to close an ActiveMQConnectionFactory + ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(); + JMSContext jmsContext = cf.createContext() + ) { - // Step 1. Create an initial context to perform the JNDI lookup. - initialContext = new InitialContext(); + // Step 5. create a jms producer + JMSProducer jmsProducer = jmsContext.createProducer(); - // Step 2. Perfom a lookup on the queue - Queue queue = (Queue)initialContext.lookup("queue/exampleQueue"); + // Step 6. Try sending a message, we don't have the appropriate privileges to do this so this will throw an exception + jmsProducer.send(queue, "A Message from JMS2!"); - // Step 3. Perform a lookup on the Connection Factory - ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("ConnectionFactory"); - - // Step 4.Create a JMS Context using the try-with-resources statement - try - ( - JMSContext jmsContext = cf.createContext() - ) - { - // Step 5. create a jms producer - JMSProducer jmsProducer = jmsContext.createProducer(); - - // Step 6. Try sending a message, we don't have the appropriate privileges to do this so this will throw an exception - jmsProducer.send(queue, "this message will fail security!"); - } - catch(JMSRuntimeException e) - { - //Step 7. we can handle the new JMSRuntimeException if we want or let the exception get handled elsewhere, the - //JMSCcontext will have been closed by the time we get to this point - System.out.println("expected exception from jmsProducer.send: " + e.getMessage()); - } - } - finally - { - // Step 8. Be sure to close our Initial Context, note that we don't have to close the JMSContext as it is auto closeable - //and closed by the vm - if (initialContext != null) - { - initialContext.close(); - } + System.out.println("Received:" + jmsContext.createConsumer(queue).receiveBody(String.class)); } } } diff --git a/examples/jms/jms-bridge/pom.xml b/examples/jms/jms-bridge/pom.xml index ac21a8ce2b..962705138f 100644 --- a/examples/jms/jms-bridge/pom.xml +++ b/examples/jms/jms-bridge/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-bridge-example + bridge jar ActiveMQ Artemis JMS Bridge Example @@ -42,115 +43,126 @@ under the License. ${project.version} - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create0 - - create - - - ${basedir}/target/server0 - ${basedir}/target/classes/activemq/server0 - - - - create1 - - create - - - ${basedir}/target/server1 - ${basedir}/target/classes/activemq/server1 - - - - start0 - - cli - - - true - ${basedir}/target/server0 - tcp://localhost:61616 - - run - - server0 - - - - start1 - - cli - - - true - ${basedir}/target/server1 - tcp://localhost:61617 - - run - - server1 - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.JMSBridgeExample - - - - stop0 - - cli - - - ${basedir}/target/server0 - - stop - - - - - stop1 - - cli - - - ${basedir}/target/server1 - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-bridge-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create0 + + create + + + ${noServer} + ${basedir}/target/server0 + ${basedir}/target/classes/activemq/server0 + + + + create1 + + create + + + ${noServer} + ${basedir}/target/server1 + ${basedir}/target/classes/activemq/server1 + + + + start0 + + cli + + + ${noServer} + true + ${basedir}/target/server0 + tcp://localhost:61616 + + run + + server0 + + + + start1 + + cli + + + ${noServer} + true + ${basedir}/target/server1 + tcp://localhost:61617 + + run + + server1 + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.JMSBridgeExample + + + + stop0 + + cli + + + ${noServer} + ${basedir}/target/server0 + + stop + + + + + stop1 + + cli + + + ${noServer} + ${basedir}/target/server1 + + stop + + + + + + + org.apache.activemq.examples.jms + bridge + ${project.version} + + + + + diff --git a/examples/jms/jms-bridge/readme.html b/examples/jms/jms-bridge/readme.html index 973abfd807..2ded7517ae 100644 --- a/examples/jms/jms-bridge/readme.html +++ b/examples/jms/jms-bridge/readme.html @@ -26,6 +26,9 @@ under the License.

        JMS Bridge Example

        + +
        To run the example, simply type mvn verify from this directory, 
        or mvn -PnoServer verify if you want to start and create the server manually.
        +

        This example shows you how to create a JMS Bridge between two ActiveMQ Artemis servers.

        The example will use two ActiveMQ Artemis servers:

        diff --git a/examples/jms/jms-completion-listener/pom.xml b/examples/jms/jms-completion-listener/pom.xml index ef5fb76209..75615514ec 100644 --- a/examples/jms/jms-completion-listener/pom.xml +++ b/examples/jms/jms-completion-listener/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-completion-listener-example + completion-listener jar ActiveMQ Artemis JMS Completion Listener Example @@ -37,71 +38,82 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.JMSCompletionListenerExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-completion-listener-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + ${basedir}/target/classes/activemq/server0 + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.JMSCompletionListenerExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + completion-listener + ${project.version} + + + + + diff --git a/examples/jms/jms-completion-listener/readme.html b/examples/jms/jms-completion-listener/readme.html index c29066a469..f9d39ade39 100644 --- a/examples/jms/jms-completion-listener/readme.html +++ b/examples/jms/jms-completion-listener/readme.html @@ -27,11 +27,12 @@ under the License.

        JMS Completion Listener Example

        +
        To run the example, simply type mvn verify from this directory, 
        or mvn -PnoServer verify if you want to start and create the server manually.
        +

        This example shows you how to send a message asynchronously to ActiveMQ Artemis and use a CompletionListener to be notified of the Broker receiving it

        Example step-by-step

        -

        To run the example, simply type mvn verify -Pexample from this directory

        1. First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the client-jndi.properties file in the directory ../common/config
        2. diff --git a/examples/jms/jms-completion-listener/src/main/java/org/apache/activemq/artemis/jms/example/JMSCompletionListenerExample.java b/examples/jms/jms-completion-listener/src/main/java/org/apache/activemq/artemis/jms/example/JMSCompletionListenerExample.java index 47a61cb57a..5de38cbeb6 100644 --- a/examples/jms/jms-completion-listener/src/main/java/org/apache/activemq/artemis/jms/example/JMSCompletionListenerExample.java +++ b/examples/jms/jms-completion-listener/src/main/java/org/apache/activemq/artemis/jms/example/JMSCompletionListenerExample.java @@ -29,6 +29,9 @@ import java.lang.IllegalStateException; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; + /** * A JMS Completion Listener Example. */ @@ -36,18 +39,14 @@ public class JMSCompletionListenerExample { public static void main(final String[] args) throws Exception { - InitialContext initialContext = null; JMSContext jmsContext = null; try { - // Step 1. Create an initial context to perform the JNDI lookup. - initialContext = new InitialContext(); - // Step 2. Perfom a lookup on the queue - Queue queue = (Queue)initialContext.lookup("queue/exampleQueue"); + Queue queue = ActiveMQJMSClient.createQueue("exampleQueue"); // Step 3. Perform a lookup on the Connection Factory - ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("ConnectionFactory"); + ConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616?confirmationWindowSize=10240"); // Step 4.Create a JMS Context jmsContext = cf.createContext(); @@ -85,11 +84,6 @@ public class JMSCompletionListenerExample } finally { - // Step 8. Be sure to close our JMS resources! - if (initialContext != null) - { - initialContext.close(); - } if (jmsContext != null) { jmsContext.close(); diff --git a/examples/jms/jms-context/pom.xml b/examples/jms/jms-context/pom.xml index d586367bec..fac041b5a2 100644 --- a/examples/jms/jms-context/pom.xml +++ b/examples/jms/jms-context/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-context-example + context jar ActiveMQ Artemis JMS Context Example @@ -37,71 +38,81 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.JMSContextExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-context-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.JMSContextExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + context + ${project.version} + + + + + diff --git a/examples/jms/jms-context/readme.html b/examples/jms/jms-context/readme.html index 253fe1bf72..822a474dc8 100644 --- a/examples/jms/jms-context/readme.html +++ b/examples/jms/jms-context/readme.html @@ -27,67 +27,9 @@ under the License.

          JMS Context Example

          +
          To run the example, simply type mvn verify from this directory, 
          or mvn -PnoServer verify if you want to start and create the server manually.
          +

          This example shows you how to send and receive a message to a JMS Queue using ActiveMQ Artemis by using a JMS Context

          A JMSContext is part of JMS 2.0 and combines the JMS Connection and Session Objects into a simple Interface

          - -

          Example step-by-step

          -

          To run the example, simply type mvn verify -Pexample from this directory

          - -
            -
          1. First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the client-jndi.properties file in the directory ../common/config
          2. -
            -           InitialContext initialContext = getContext();
            -        
            - -
          3. We look-up the JMS queue object from JNDI
          4. -
            -           Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");
            -        
            - -
          5. We look-up the JMS connection factory object from JNDI
          6. -
            -           ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
            -        
            - -
          7. We create a JMS context
          8. -
            -           jmsContext = cf.createContext();
            -        
            - -
          9. We create a JMS Producer, set the delivery mode and send a message all in one line. Note that we don't pass - a message to the send method but just a String.
          10. -
            -           jmsContext.createProducer().setDeliveryMode(DeliveryMode.PERSISTENT).send(queue, "this is a string")
            -        
            - -
          11. We create a JMS message consumer and receive the payload of the message directly
          12. -
            -          String payLoad = jmsContext.createConsumer(queue).receiveBody(String.class);
            -       
            - -
          13. We create a JMS text message that we are going to send.
          14. -
            -           TextMessage message = session.createTextMessage("This is a text message");
            -        
            - -
          15. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
          16. - -
            -           finally
            -           {
            -              if (initialContext != null)
            -              {
            -                 initialContext.close();
            -              }
            -              if (jmsContext != null)
            -              {
            -                 jmsContext.close();
            -              }
            -           }
            -        
            - - - -
          diff --git a/examples/jms/jms-context/src/main/java/org/apache/activemq/artemis/jms/example/JMSContextExample.java b/examples/jms/jms-context/src/main/java/org/apache/activemq/artemis/jms/example/JMSContextExample.java index bb8457f49d..27be3b025e 100644 --- a/examples/jms/jms-context/src/main/java/org/apache/activemq/artemis/jms/example/JMSContextExample.java +++ b/examples/jms/jms-context/src/main/java/org/apache/activemq/artemis/jms/example/JMSContextExample.java @@ -16,12 +16,12 @@ */ package org.apache.activemq.artemis.jms.example; -import javax.jms.ConnectionFactory; import javax.jms.DeliveryMode; import javax.jms.JMSContext; import javax.jms.Queue; -import javax.naming.InitialContext; -import java.lang.Exception; + +import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; /** * A simple JMS Queue example that creates a producer and consumer on a queue and sends then receives a message. @@ -30,41 +30,24 @@ public class JMSContextExample { public static void main(final String[] args) throws Exception { - InitialContext initialContext = null; - JMSContext jmsContext = null; - try + // Instantiate the queue + Queue queue = ActiveMQJMSClient.createQueue("exampleQueue"); + + // Instantiate the ConnectionFactory (Using the default URI on this case) + // Also instantiate the jmsContext + // Using closeable interface + try (ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(); + JMSContext jmsContext = cf.createContext()) { - // Step 1. Create an initial context to perform the JNDI lookup. - initialContext = new InitialContext(); - - // Step 2. Perfom a lookup on the queue - Queue queue = (Queue)initialContext.lookup("queue/exampleQueue"); - - // Step 3. Perform a lookup on the Connection Factory - ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("ConnectionFactory"); - - // Step 4.Create a JMS Context - jmsContext = cf.createContext(); - - // Step 5. Create a message producer, note that we can chain all this into one statement + // Create a message producer, note that we can chain all this into one statement jmsContext.createProducer().setDeliveryMode(DeliveryMode.PERSISTENT).send(queue, "this is a string"); - // Step 6. Create a Consumer and receive the payload of the message direct. + // Create a Consumer and receive the payload of the message direct. String payLoad = jmsContext.createConsumer(queue).receiveBody(String.class); System.out.println("payLoad = " + payLoad); + } - finally - { - // Step 7. Be sure to close our JMS resources! - if (initialContext != null) - { - initialContext.close(); - } - if (jmsContext != null) - { - jmsContext.close(); - } - } + } } diff --git a/examples/jms/jms-context/src/main/resources/jndi.properties b/examples/jms/jms-context/src/main/resources/jndi.properties deleted file mode 100644 index 93537c415a..0000000000 --- a/examples/jms/jms-context/src/main/resources/jndi.properties +++ /dev/null @@ -1,20 +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. - -java.naming.factory.initial=org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory -connectionFactory.ConnectionFactory=tcp://localhost:61616 -queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/jms-shared-consumer/pom.xml b/examples/jms/jms-shared-consumer/pom.xml index af55f861f3..c4a2b0a46c 100644 --- a/examples/jms/jms-shared-consumer/pom.xml +++ b/examples/jms/jms-shared-consumer/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-shared-consumer-example + shared-consumer jar ActiveMQ Artemis JMS Shared Consumer Example @@ -37,71 +38,83 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.JMSSharedConsumerExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-shared-consumer-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + ${basedir}/target/server0 + ${basedir}/target/classes/activemq/server0 + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.JMSSharedConsumerExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + shared-consumer + ${project.version} + + + + + diff --git a/examples/jms/jms-shared-consumer/readme.html b/examples/jms/jms-shared-consumer/readme.html index 54e57f9f1f..edf6c33c43 100644 --- a/examples/jms/jms-shared-consumer/readme.html +++ b/examples/jms/jms-shared-consumer/readme.html @@ -27,12 +27,13 @@ under the License.

          JMS Shared Consumer Example

          +
          To run the example, simply type mvn verify from this directory, 
          or mvn -PnoServer verify if you want to start and create the server manually.
          +

          This example shows you how can use shared consumers to share a subscription on a topic. In JMS 1.1 this was not allowed and so caused a scalability issue. In JMS 2 this restriction has been lifted so you can share the load across different threads and connections.

          Example step-by-step

          -

          To run the example, simply type mvn verify -Pexample from this directory

          1. First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the client-jndi.properties file in the directory ../common/config
          2. diff --git a/examples/jms/jmx/pom.xml b/examples/jms/jmx/pom.xml index 802025d726..aaedf6833e 100644 --- a/examples/jms/jmx/pom.xml +++ b/examples/jms/jmx/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-jmx-example + jmx jar ActiveMQ Artemis JMS "JMX" Example @@ -46,76 +47,81 @@ under the License. artemis-jms-client ${project.version} - - org.apache.geronimo.specs - geronimo-jms_2.0_spec - - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=3000 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.JMXExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-jmx-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=3000 + -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false + + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.JMXExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + jmx + ${project.version} + + + + + diff --git a/examples/jms/jmx/readme.html b/examples/jms/jmx/readme.html index 462ec6a808..2ec87e7639 100644 --- a/examples/jms/jmx/readme.html +++ b/examples/jms/jmx/readme.html @@ -27,6 +27,8 @@ under the License.

            JMX Management Example

            +
            To run the example, simply type mvn verify from this directory, 
            or mvn -PnoServer verify if you want to start and create the server manually.
            +

            This example shows how to manage ActiveMQ Artemis using JMX

            Example configuration

            @@ -40,12 +42,11 @@ under the License. -Dcom.sun.management.jmxremote.authenticate=false

            These properties are explained in the Java 5 Management guide - (please note that for this example, we will disable user authentication for simplicity sake).

            -

            With these properties, ActiveMQ Artemis server will be manageable remotely using standard JMX URL on port 3000.

            + (please note that for this example, we will disable user authentication for simplicity sake).

            +

            With these properties, ActiveMQ Artemis server will be manageable remotely using standard JMX URL on port 3000.

            - +

            Example step-by-step

            -

            To run the example, simply type mvn verify -Pexample from this directory

            1. First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get its properties from client-jndi.properties
            2. @@ -66,7 +67,7 @@ under the License.
                       
                           connection = cf.createConnection();
                       
              - +
            3. We create a JMS session. The session is created as non transacted and will auto acknowledge messages.
            4.              Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
              @@ -89,7 +90,7 @@ under the License.
               
                       

              Now that we have a message in the queue, we will manage the queue by retrieving the number of messages in the queue (i.e. 1) and by removing the message which has been sent in step 8.

              - +
            5. We retrieve the ObjectName corresponding to the queue using a helper class ObjectNameBuilder
            6.                ObjectName on = ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queue.getQueueName());
              @@ -104,7 +105,7 @@ under the License.
                       
                          TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
                       
              - +
            7. We create a JMSQueueControl proxy to manage the queue on the server
            8.              JMSQueueControl queueControl = (JMSQueueControl)MBeanServerInvocationHandler.newProxyInstance(mbsc,
              @@ -113,7 +114,7 @@ under the License.
                                                                                                             false);
                            
                       
              - +
            9. We use this mbean proxy to retrieve the number of messages in the queue using the getMessageCount method
            10.              System.out.println(queueControl.getName() + " contains " + queueControl.getMessageCount() + " messages");
              @@ -123,36 +124,36 @@ under the License.
                       
                           System.out.println("message has been removed: " + queueControl.removeMessage(message.getJMSMessageID()));
                       
              - +
            11. We use again the mbean proxy to retrieve the number of messages. This time, it will display 0 messages
            12.              System.out.println(queueControl.getName() + " contains " + queueControl.getMessageCount() + " messages");
                       
              - +
            13. Now we have finish the management operations, we close the JMX connector
            14.              connector.close()
                       

              We will now try to consume the message sent to the queue but it won't be there: it has been removed by the management operation

              - +
            15. We create a JMS message consumer on the queue
            16.              MessageConsumer messageConsumer = session.createConsumer(queue);
                       
              - +
            17. We start the connection. In order for delivery to occur on any consumers or subscribers on a connection, the connection must be started
            18.              connection.start();
                       
              - +
            19. We try to receive a message from the queue. Since there is none, the call will timeout after 5000ms and messageReceived will be null
            20.              TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
                           System.out.println("Received message: " + messageReceived);
                       
              - +
            21. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
            22. @@ -169,9 +170,9 @@ under the License.
                          }
                       
            - +

            More information

            - +
            • User Manual's Using Management Via JMX chapter
            • Java 5 Management guide
            • diff --git a/examples/jms/large-message/pom.xml b/examples/jms/large-message/pom.xml index cc354e6513..2382cdf742 100644 --- a/examples/jms/large-message/pom.xml +++ b/examples/jms/large-message/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-large-message-example + large-message jar ActiveMQ Artemis JMS Large Message Example @@ -42,50 +43,46 @@ under the License. ${project.version} - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - - - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.LargeMessageExample - - ${basedir}/target/server0 - - - - - - - org.apache.activemq.examples.jms - artemis-jms-large-message-example - ${project.version} - - - - - - - + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.LargeMessageExample + + ${basedir}/target/server0 + + + + + + + org.apache.activemq.examples.jms + large-message + ${project.version} + + + + + diff --git a/examples/jms/large-message/readme.html b/examples/jms/large-message/readme.html index 6f0e6f831e..1583a2ba1c 100644 --- a/examples/jms/large-message/readme.html +++ b/examples/jms/large-message/readme.html @@ -27,6 +27,9 @@ under the License.

              Large Message Example

              +
              To run the example, simply type mvn verify from this directory, This example will start and stop the server since it will look for a failure.
              + +

              This example shows you how to send and receive very large messages with ActiveMQ Artemis.

              ActiveMQ Artemis supports the sending and receiving of huge messages, much larger than can fit in available RAM on the client or server. Effectively the only limit to message size is the amount of disk space you have on the server.

              @@ -35,8 +38,7 @@ under the License.

              In order to do this ActiveMQ Artemis provides an extension to JMS where you can use an InputStream or OutputStream as the source and destination for your messages. You can send messages as large as it would fit in your disk.

              You may also choose to read LargeMessages using the regular ByteStream or ByteMessage methods, but using the InputStream and OutputStream will provide you a much better performance

              -

              Example step-by-step

              -

              To run the example, simply type mvn verify -Pexample from this directory

              +

              Example step-by-step

              In this example we limit both the server and the client to be running in a maximum of 50MB of RAM, and we send a message with a body of size 256MB.

              ActiveMQ Artemis can support much large message sizes but we @@ -95,17 +97,17 @@ under the License. file, however we could use any InputStream not just a FileInputStream.

              
                        FileInputStream fileInputStream = new FileInputStream(fileInput);
              -         
              +
                        BufferedInputStream bufferedInput = new BufferedInputStream(fileInputStream);
              -         
              +
                        message.setObjectProperty("JMS_AMQ_InputStream", bufferedInput);
                       
              - +
            • Send the Message.
            • 
                        producer.send(message);
                        
              - +
            • We send message to the queue. After the send completion the message file will be located at ./build/data/largeMessages
            • @@ -116,7 +118,7 @@ under the License.
                       To demonstrate that that we're not simply streaming the message from sending to consumer, we stop
                       the server and restart it before consuming the message. This demonstrates that the large message gets persisted, like a
                       normal persistent message, on the server. If you look at ./build/data/largeMessages you will see the largeMessage
              -        stored on disk the server.        
              +        stored on disk the server.
                       
                         
                          
              @@ -149,7 +151,7 @@ under the License.
                       MessageConsumer messageConsumer = session.createConsumer(queue);
               
                       connection.start();
              -           
              +
                          
                       
              @@ -157,7 +159,7 @@ under the License. an empty body.
              BytesMessage messageReceived = (BytesMessage)messageConsumer.receive(120000);
                       
              - +
            • We set an OutputStream on the message. This causes the message body to be written to the OutputStream until there are no more bytes to be written. You don't have to use a FileOutputStream, you can use any OutputStream. @@ -169,14 +171,14 @@ under the License. FileOutputStream fileOutputStream = new FileOutputStream(outputFile); BufferedOutputStream bufferedOutput = new BufferedOutputStream(fileOutputStream); - +
            • - -
            • This will save the stream and wait until the entire message is written before continuing.
            • + +
            • This will save the stream and wait until the entire message is written before continuing.
            • 
                        messageReceived.setObjectProperty("JMS_AMQ_SaveStream", bufferedOutput);
                       
              - +
            • Be sure to close our resources!
            • diff --git a/examples/jms/last-value-queue/pom.xml b/examples/jms/last-value-queue/pom.xml
              index 15e9d38818..6f5e89a27b 100644
              --- a/examples/jms/last-value-queue/pom.xml
              +++ b/examples/jms/last-value-queue/pom.xml
              @@ -18,7 +18,8 @@ specific language governing permissions and limitations
               under the License.
               -->
               
              -
              +
                  4.0.0
               
                  
              @@ -27,7 +28,7 @@ under the License.
                     1.0.1-SNAPSHOT
                  
               
              -   artemis-jms-last-value-queue-example
              +   last-value-queue
                  jar
                  ActiveMQ Artemis JMS Last Value Queue Example
               
              @@ -37,71 +38,81 @@ under the License.
               
                  
                     
              -         org.apache.geronimo.specs
              -         geronimo-jms_2.0_spec
              +         org.apache.activemq
              +         artemis-jms-client
              +         ${project.version}
                     
                  
               
                  
                     
              -         example
              -         
              -            
              -               
              -                  org.apache.activemq
              -                  artemis-maven-plugin
              -                  
              -                     
              -                        create
              -                        
              -                           create
              -                        
              -                     
              -                     
              -                        start
              -                        
              -                           cli
              -                        
              -                        
              -                           true
              -                           tcp://localhost:61616
              -                           
              -                              run
              -                           
              -                        
              -                     
              -                     
              -                        runClient
              -                        
              -                           runClient
              -                        
              -                        
              -                           org.apache.activemq.artemis.jms.example.LastValueQueueExample
              -                        
              -                     
              -                     
              -                        stop
              -                        
              -                           cli
              -                        
              -                        
              -                           
              -                              stop
              -                           
              -                        
              -                     
              -                  
              -                  
              -                     
              -                        org.apache.activemq.examples.jms
              -                        artemis-jms-last-value-queue-example
              -                        ${project.version}
              -                     
              -                  
              -                
              -            
              -         
              +         
              +         noServer
              +         
              +            true
              +         
                     
                  
              +   
              +      
              +         
              +            org.apache.activemq
              +            artemis-maven-plugin
              +            
              +               
              +                  create
              +                  
              +                     create
              +                  
              +                  
              +                     ${noServer}
              +                  
              +               
              +               
              +                  start
              +                  
              +                     cli
              +                  
              +                  
              +                     ${noServer}
              +                     true
              +                     tcp://localhost:61616
              +                     
              +                        run
              +                     
              +                  
              +               
              +               
              +                  runClient
              +                  
              +                     runClient
              +                  
              +                  
              +                     org.apache.activemq.artemis.jms.example.LastValueQueueExample
              +                  
              +               
              +               
              +                  stop
              +                  
              +                     cli
              +                  
              +                  
              +                     ${noServer}
              +                     
              +                        stop
              +                     
              +                  
              +               
              +            
              +            
              +               
              +                  org.apache.activemq.examples.jms
              +                  last-value-queue
              +                  ${project.version}
              +               
              +            
              +         
              +      
              +   
               
               
              diff --git a/examples/jms/last-value-queue/readme.html b/examples/jms/last-value-queue/readme.html
              index 303c136882..1ecb6e83d5 100644
              --- a/examples/jms/last-value-queue/readme.html
              +++ b/examples/jms/last-value-queue/readme.html
              @@ -27,25 +27,26 @@ under the License.
                 
                    

              Last-Value Queue Example

              +
              To run the example, simply type mvn verify from this directory, 
              or mvn -PnoServer verify if you want to start and create the server manually.
              +

              This example shows you how to configure and use last-value queues.

              Last-Value queues are special queues which discard any messages when a newer message with the same value for a well-defined Last-Value property is put in the queue. In other words, a Last-Value queue only retains the last value.

              A typical example for Last-Value queue is for stock prices, where you are only interested by the latest value for a particular stock.

              - +

              The example will send 3 messages with the same Last-Value property to a to a Last-Value queue.
              We will browse the queue and see that only the last message is in the queue, the first two messages have been discarded.
              We will then consume from the queue the last message.

              - +

              Example setup

              Last-Value queues are defined in the configuration file broker.xml:

                        <address-setting match="jms.queue.lastValueQueue">
                               <last-value-queue>true</last-value-queue>
                        </address-setting>
              -     
              - +
              +

              Example step-by-step

              -

              To run the example, simply type mvn verify -Pexample from this directory

              1. First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the client-jndi.properties
              2. @@ -68,7 +69,7 @@ under the License.
                             Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
                             MessageProducer producer = session.createProducer(queue);
                        
                - +
              3. We will create and send a text message with the Last-Value property set to STOCK_NAME
              4.             TextMessage message = session.createTextMessage("1st message with Last-Value property set");
                @@ -76,7 +77,7 @@ under the License.
                            producer.send(message);
                            System.out.format("Sent message: %s\n", message.getText());
                        
                - +

                The Last-Value key is defined in ActiveMQ's MessageImpl class. Its value is "_AMQ_LVQ_NAME"

              5. We will create and send a second text message with the Last-Value property set to STOCK_NAME
              6. @@ -111,14 +112,14 @@ under the License. browser.close(); - +

                We will now consume the message on the queue

              7. We create a JMS message consumer on the queue
              8.              MessageConsumer messageConsumer = session.createConsumer(queue);
                         
                - +
              9. We start the connection. In order for delivery to occur on any consumers or subscribers on a connection, the connection must be started
              10.             connection.start();
                @@ -129,7 +130,7 @@ under the License.
                             TextMessage messageReceived = (TextMessage)messageConsumer.receive(5000);
                             System.out.format("Received message: %s\n", messageReceived.getText());
                         
                - +
              11. We will try to receive another message but there is no other on the queue. The receive method will timeout after 5 seconds
              12.              messageReceived = (TextMessage)messageConsumer.receive(5000);
                @@ -151,9 +152,9 @@ under the License.
                            }
                         
              - +

              More information

              - + diff --git a/examples/jms/last-value-queue/src/main/java/org/apache/activemq/artemis/jms/example/LastValueQueueExample.java b/examples/jms/last-value-queue/src/main/java/org/apache/activemq/artemis/jms/example/LastValueQueueExample.java index 72b001b295..2c375037e1 100644 --- a/examples/jms/last-value-queue/src/main/java/org/apache/activemq/artemis/jms/example/LastValueQueueExample.java +++ b/examples/jms/last-value-queue/src/main/java/org/apache/activemq/artemis/jms/example/LastValueQueueExample.java @@ -16,17 +16,17 @@ */ package org.apache.activemq.artemis.jms.example; -import java.util.Enumeration; - import javax.jms.Connection; -import javax.jms.ConnectionFactory; import javax.jms.MessageConsumer; import javax.jms.MessageProducer; import javax.jms.Queue; import javax.jms.QueueBrowser; import javax.jms.Session; import javax.jms.TextMessage; -import javax.naming.InitialContext; +import java.util.Enumeration; + +import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; /** * This example shows how to configure and use a Last-Value queues. @@ -37,17 +37,13 @@ public class LastValueQueueExample public static void main(final String[] args) throws Exception { Connection connection = null; - InitialContext initialContext = null; try { - // Step 1. Create an initial context to perform the JNDI lookup. - initialContext = new InitialContext(); + // Step 2. new Queue + Queue queue = ActiveMQJMSClient.createQueue("exampleQueue"); - // Step 2. Perfom a lookup on the queue - Queue queue = (Queue)initialContext.lookup("queue/exampleQueue"); - - // Step 3. Perform a lookup on the Connection Factory - ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("ConnectionFactory"); + // Step 3. new Connection Factory + ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(); // Step 4.Create a JMS Connection, session and producer on the queue connection = cf.createConnection(); @@ -99,15 +95,11 @@ public class LastValueQueueExample messageReceived = (TextMessage)messageConsumer.receive(5000); System.out.format("Received message: %s%n", messageReceived); - initialContext.close(); + cf.close(); } finally { // Step 13. Be sure to close our JMS resources! - if (initialContext != null) - { - initialContext.close(); - } if (connection != null) { connection.close(); diff --git a/examples/jms/management-notifications/pom.xml b/examples/jms/management-notifications/pom.xml index 8caa70f5b6..a9adba33a0 100644 --- a/examples/jms/management-notifications/pom.xml +++ b/examples/jms/management-notifications/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-management-notifications-example + management-notifications jar ActiveMQ Artemis JMS Management Notifications Example @@ -37,71 +38,81 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.ManagementNotificationExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-management-notifications-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.ManagementNotificationExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + management-notifications + ${project.version} + + + + + diff --git a/examples/jms/management-notifications/readme.html b/examples/jms/management-notifications/readme.html index 20406cb686..6a76f62f7d 100644 --- a/examples/jms/management-notifications/readme.html +++ b/examples/jms/management-notifications/readme.html @@ -26,6 +26,9 @@ under the License.

              Management Notification Example

              + +
              To run the example, simply type mvn verify from this directory, 
              or mvn -PnoServer verify if you want to start and create the server manually.
              +

              This example shows how to receive management notifications from ActiveMQ Artemis using JMS Messages.

              ActiveMQ Artemis servers emit management notifications when events of interest occur (consumers are created or closed, destinations are created or deleted, security authentication fails, etc.).
              @@ -33,7 +36,7 @@ under the License. from a well-known destination.

              This example will setup a JMS MessageListener to receive management notifications. We will also perform normal JMS operations to see the kind of notifications they trigger.

              - +

              Example configuration

              ActiveMQ Artemis can configured to send JMS messages when management notifications are emitted on the server.

              @@ -42,7 +45,7 @@ under the License.
                        <management-notification-address>jms.topic.notificationsTopic</management-notification-address>
                    
              - +

              Since we want to lookup the notifications topic using JNDI, we also declare it in activemq-jms.xml

                        <topic name="notificationsTopic">
              @@ -59,10 +62,9 @@ under the License.
                           <permission type="deleteNonDurableQueue" roles="guest"/>
                        </security-setting>
                    
              - +

              Example step-by-step

              -

              To run the example, simply type mvn verify -Pexample from this directory

              -
                +x
                1. First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get its properties from client-jndi.properties
                2.              InitialContext initialContext = getContext(0);
                  @@ -84,7 +86,7 @@ under the License.
                               Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
                               MessageProducer producer = session.createProducer(queue);
                           
                  - +
                3. We look up the JMS Topic used to receive the notifications from JNDI
                4.              Topic notificationsTopic = (Topic) initialContext.lookup("/topic/notificationsTopic");
                  @@ -112,23 +114,23 @@ under the License.
                                    {
                                    }
                                    System.out.println("------------------------");
                  -              }            
                  +              }
                              });
                           
                  - +
                5. We start the connection to receive messages
                6.              connection.start();
                           
                  - -

                  Now that a message listener is setup to receive management notifications, we will perform regular JMS operations to + +

                  Now that a message listener is setup to receive management notifications, we will perform regular JMS operations to see what kind of notifications are triggered

                  - +
                7. We create a JMS message consumer on the example queue
                8.              MessageConsumer consumer = session.createConsumer(queue);
                           
                  - +

                  This will generate a CONSUMER_CREATED notification:

                               ------------------------
                  @@ -143,7 +145,7 @@ under the License.
                           

                  The notification tells us that a consumer was created for the JMS queue exampleQueue. When the notification was emitted, this consumer was the only one for the queue

                  - +
                9. We close this consumer
                10.              consumer.close();
                  @@ -170,10 +172,10 @@ under the License.
                               {
                                  cf.createConnection("not.a.valid.user", "not.a.valid.password");
                               } catch (JMSException e)
                  -            {            
                  +            {
                               }
                           
                  - +

                  This will generate a SECURITY_AUTHENTICATION_VIOLATION notification:

                               ------------------------
                  @@ -185,7 +187,7 @@ under the License.
                               
                           

                  The notification tells us that a user named not.a.valid.user failed to authenticate when creating a connection to ActiveMQ Artemis.

                  - +
                11. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
                12. @@ -202,12 +204,12 @@ under the License.
                              }
                           
                - +

                More information

                - + +
            diff --git a/examples/jms/management/pom.xml b/examples/jms/management/pom.xml index d287c28184..b84b8f557a 100644 --- a/examples/jms/management/pom.xml +++ b/examples/jms/management/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-management-example + management jar ActiveMQ Artemis JMS Management Example @@ -41,72 +42,77 @@ under the License. artemis-jms-client ${project.version} - - org.apache.geronimo.specs - geronimo-jms_2.0_spec - - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.ManagementExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-management-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.ManagementExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + management + ${project.version} + + + + + diff --git a/examples/jms/message-counters/pom.xml b/examples/jms/message-counters/pom.xml index 7cd17e3508..a046a3783e 100644 --- a/examples/jms/message-counters/pom.xml +++ b/examples/jms/message-counters/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-message-counters-example + message-counters jar ActiveMQ Artemis JMS Message Counter Example @@ -36,85 +37,90 @@ under the License. - - org.apache.activemq - artemis-jms-client - ${project.version} - org.apache.activemq artemis-server ${project.version} - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=3001 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.MessageCounterExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-message-counters-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=3001 + -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false + + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.MessageCounterExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + message-counters + ${project.version} + + + + + diff --git a/examples/jms/message-counters/readme.html b/examples/jms/message-counters/readme.html index 63b5d97f99..69cbef3c0d 100644 --- a/examples/jms/message-counters/readme.html +++ b/examples/jms/message-counters/readme.html @@ -27,6 +27,8 @@ under the License.

            JMS Message Counter Example

            +
            To run the example, simply type mvn verify from this directory, 
            or mvn -PnoServer verify if you want to start and create the server manually.
            +

            This example shows you how to use message counters to obtain message information for a JMS queue.

            The example will show how to configure sampling of message counters.
            We will produce and consume 1 message from a queue. Interleaved with the JMS operation, we will retrieve the queue's message counters @@ -45,9 +47,8 @@ under the License. the message-counter-max-day-history parameter.

            The sample period and the max day history parameters have a small impact on the performance of ActiveMQ Artemis (the resources taken to sample a queue are not available to the system's normal use). You should set these parameters accordingly to the use and throughput of your messages.

            - +

            Example step-by-step

            -

            To run the example, simply type mvn verify -Pexample from this directory

            1. First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the client-jndi.properties file in the directory ../common/config
            2. @@ -70,7 +71,7 @@ under the License.
                           QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
                           MessageProducer producer = session.createProducer(queue);
                      
              - +
            3. We create and send a JMS text message
            4.              TextMessage message = session.createTextMessage("This is a text message");
              @@ -84,7 +85,7 @@ under the License.
                           System.out.println("Sleep a little bit to have the queue sampled...");
                           Thread.sleep(3000);
                       
              - +

              We now need to retrieve the message counters. They're available from the JMS Queue management resource. In this example, we will retrieve them using JMX (see the JMX example for a more complete description). You can also use JMS message to retrieve them (see the Management example to learn about managing ActiveMQ Artemis using JMS messages).

              @@ -106,12 +107,12 @@ under the License. String counters = queueControl.listMessageCounter(); MessageCounterInfo messageCounter = MessageCounterInfo.fromJSON(counters);> - +
            5. We display the message counters
            6.              displayMessageCounter(messageCounter);
                       
              - +

              The message counter contains a variety of metrics on the queue which is sampled (total messages added to the queue, current depth of the queue, deltas since the last sample, timestamp of the last message added, timestamp of the last sample, etc.)

              @@ -119,34 +120,34 @@ under the License.
                           private void displayMessageCounter(MessageCounterInfo counter)
                           {
                              System.out.format("%s (sample updated at %s)\n",  counter.getName(), counter.getUdpateTimestamp());
              -               System.out.format("   %s message(s) added to the queue (since last sample: %s)\n", counter.getCount(), 
              +               System.out.format("   %s message(s) added to the queue (since last sample: %s)\n", counter.getCount(),
                                                                                                                 counter.getCountDelta());
                              System.out.format("   %s message(s) in the queue (since last sample: %s)\n", counter.getDepth(),
                                                                                                           counter.getDepthDelta());
                              System.out.format("   last message added at %s\n\n", counter.getLastAddTimestamp());
                           }
                       
              - +
            7. We sleep again to have the queue sampled
            8.              System.out.println("Sleep a little bit again...");
                           Thread.sleep(3000);
                       
              - +
            9. We list the message counters again
            10.              counters = queueControl.listMessageCounter();
                           messageCounter = MessageCounterInfo.fromJSON(counters);
                           displayMessageCounter(messageCounter);
                       
              - +

              We will now consume a message from the queue before listing a last time the message counters

              - +
            11. We create a consumer for the queue
            12.              MessageConsumer consumer = session.createConsumer(queue);
                       
              - +
            13. We start the connection to receive messages on the consumer
            14.             connection.start();
              @@ -157,13 +158,13 @@ under the License.
                          TextMessage messageReceived = (TextMessage)consumer.receive(5000);
                          System.out.format("Received message: %s\n\n", messageReceived.getText());
                       
              - +
            15. We sleep one last time to have the queue sampled
            16.              System.out.println("Sleep a little bit one last time...");
                           Thread.sleep(3000);
                       
              - +
            17. We list the message counters a final time (this time with no message in the queue)
            18.              counters = queueControl.listMessageCounter();
              @@ -171,7 +172,7 @@ under the License.
                           displayMessageCounter(messageCounter);
                       
              -

              +

            19. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
            20. @@ -188,9 +189,9 @@ under the License.
                          }
                       
            - +
          3. User Manual's Message Counters chapter
          4. -
          5. MessageCounterInfo is a helper class used +
          6. MessageCounterInfo is a helper class used to create a MessageCounterInfo object from the JSON String which represents message counters
          7. diff --git a/examples/jms/message-group/pom.xml b/examples/jms/message-group/pom.xml index cfd67fbe68..cfd354c32d 100644 --- a/examples/jms/message-group/pom.xml +++ b/examples/jms/message-group/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-message-group-example + message-group jar ActiveMQ Artemis JMS Message Group Example @@ -37,71 +38,81 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.MessageGroupExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-message-group-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.MessageGroupExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + message-group + ${project.version} + + + + + diff --git a/examples/jms/message-group/readme.html b/examples/jms/message-group/readme.html index e44aa51cea..3513e8e4ec 100644 --- a/examples/jms/message-group/readme.html +++ b/examples/jms/message-group/readme.html @@ -27,13 +27,15 @@ under the License.

            Message Group Example

            +
            To run the example, simply type mvn verify from this directory, 
            or mvn -PnoServer verify if you want to start and create the server manually.
            +

            This example shows you how to configure and use message groups with ActiveMQ Artemis.

            - +

            Message groups are sets of messages that has the following characteristics:

          8. Messages in a message group share the same group id, i.e. they have same JMSXGroupID string property values.
          9. Messages in a message group will be all delivered to no more than one of the queue's consumers. The consumer that receives the first message of a group will receive all the messages that belong to the group.
          10. - +

            You can make any message belong to a message group by setting its 'JMXGroupID' string property to the group id. In this example we create a message group 'Group-0'. And make such a message group of 10 messages. It also create two consumers on the queue where the 10 'Group-0' group messages are to be sent. You can see that with message grouping enabled, all the 10 messages will be received by @@ -45,7 +47,6 @@ under the License. be part of this message group.

            Example step-by-step

            -

            To run the example, simply type mvn verify -Pexample from this directory

            1. First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the client-jndi.properties file in the directory ../common/config
            2. @@ -140,12 +141,12 @@ under the License. }
            - +

            More information

            - + - + diff --git a/examples/jms/message-group/src/main/java/org/apache/activemq/artemis/jms/example/MessageGroupExample.java b/examples/jms/message-group/src/main/java/org/apache/activemq/artemis/jms/example/MessageGroupExample.java index ea7e447ff8..7acf3c4b67 100644 --- a/examples/jms/message-group/src/main/java/org/apache/activemq/artemis/jms/example/MessageGroupExample.java +++ b/examples/jms/message-group/src/main/java/org/apache/activemq/artemis/jms/example/MessageGroupExample.java @@ -16,11 +16,7 @@ */ package org.apache.activemq.artemis.jms.example; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - import javax.jms.Connection; -import javax.jms.ConnectionFactory; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageConsumer; @@ -29,7 +25,11 @@ import javax.jms.MessageProducer; import javax.jms.Queue; import javax.jms.Session; import javax.jms.TextMessage; -import javax.naming.InitialContext; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; /** * A simple JMS Queue example that sends and receives message groups. @@ -40,17 +40,14 @@ public class MessageGroupExample { final Map messageReceiverMap = new ConcurrentHashMap(); Connection connection = null; - InitialContext initialContext = null; try { - // Step 1. Create an initial context to perform the JNDI lookup. - initialContext = new InitialContext(); // Step 2. Perform a lookup on the queue - Queue queue = (Queue)initialContext.lookup("queue/exampleQueue"); + Queue queue = ActiveMQJMSClient.createQueue("queue/exampleQueue"); // Step 3. Perform a lookup on the Connection Factory - ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("ConnectionFactory"); + ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(); // Step 4. Create a JMS Connection connection = cf.createConnection(); @@ -95,14 +92,12 @@ public class MessageGroupExample throw new IllegalStateException("Group message [" + grpMsg.getText() + "[ went to wrong receiver: " + receiver); } } + + cf.close(); } finally { // Step 11. Be sure to close our JMS resources! - if (initialContext != null) - { - initialContext.close(); - } if (connection != null) { connection.close(); diff --git a/examples/jms/message-group2/pom.xml b/examples/jms/message-group2/pom.xml index 6f23575c39..46eed3a711 100644 --- a/examples/jms/message-group2/pom.xml +++ b/examples/jms/message-group2/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-message-group2-example + message-group2 jar ActiveMQ Artemis JMS Message Group Example 2 @@ -37,71 +38,81 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.MessageGroup2Example - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-message-group2-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.MessageGroup2Example + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + message-group2 + ${project.version} + + + + + diff --git a/examples/jms/message-group2/readme.html b/examples/jms/message-group2/readme.html index a5d85ac464..911852c2cc 100644 --- a/examples/jms/message-group2/readme.html +++ b/examples/jms/message-group2/readme.html @@ -27,13 +27,16 @@ under the License.

            Message Group Example

            +
            To run the example, simply type mvn verify from this directory, 
            or mvn -PnoServer verify if you want to start and create the server manually.
            + +

            This example shows you how to configure and use message groups via a connection factory with ActiveMQ Artemis.

            - +

            Message groups are sets of messages that has the following characteristics:

          11. Messages in a message group share the same group id, i.e. they have same JMSXGroupID string property values.
          12. Messages in a message group will be all delivered to no more than one of the queue's consumers. The consumer that receives the first message of a group will receive all the messages that belongs to the group.
          13. - +

            You can make any message belong to a message group by setting a 'group-id' on the connection factory. All producers created via this connection factory will set that group id on its messages. In this example we set the group id 'Group-0'on a connection factory and send messages via 2 different producers and check that only 1 consumer receives them.

            @@ -43,7 +46,6 @@ under the License. be part of this message group.

            Example step-by-step

            -

            To run the example, simply type mvn verify -Pexample from this directory

            1. First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the client-jndi.properties file in the directory ../common/config
            2. @@ -148,12 +150,12 @@ under the License.
                          }
                       
            - +

            More information

            - + - + diff --git a/examples/jms/message-group2/src/main/java/org/apache/activemq/artemis/jms/example/MessageGroup2Example.java b/examples/jms/message-group2/src/main/java/org/apache/activemq/artemis/jms/example/MessageGroup2Example.java index d53a125fef..c70c932bfa 100644 --- a/examples/jms/message-group2/src/main/java/org/apache/activemq/artemis/jms/example/MessageGroup2Example.java +++ b/examples/jms/message-group2/src/main/java/org/apache/activemq/artemis/jms/example/MessageGroup2Example.java @@ -16,11 +16,7 @@ */ package org.apache.activemq.artemis.jms.example; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - import javax.jms.Connection; -import javax.jms.ConnectionFactory; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageConsumer; @@ -29,7 +25,11 @@ import javax.jms.MessageProducer; import javax.jms.Queue; import javax.jms.Session; import javax.jms.TextMessage; -import javax.naming.InitialContext; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; /** * A simple JMS Queue example that sends and receives message groups. @@ -42,17 +42,13 @@ public class MessageGroup2Example { final Map messageReceiverMap = new ConcurrentHashMap(); Connection connection = null; - InitialContext initialContext = null; try { - //Step 1. Create an initial context to perform the JNDI lookup. - initialContext = new InitialContext(); - //Step 2. Perform a lookup on the queue - Queue queue = (Queue) initialContext.lookup("queue/exampleQueue"); + Queue queue = ActiveMQJMSClient.createQueue("exampleQueue"); //Step 3. Perform a lookup on the Connection Factory - ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("ConnectionFactory"); + ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616?groupID=Group-0"); //Step 4. Create a JMS Connection connection = cf.createConnection(); @@ -110,10 +106,6 @@ public class MessageGroup2Example finally { //Step 11. Be sure to close our JMS resources! - if (initialContext != null) - { - initialContext.close(); - } if(connection != null) { connection.close(); diff --git a/examples/jms/message-group2/src/main/resources/jndi.properties b/examples/jms/message-group2/src/main/resources/jndi.properties deleted file mode 100644 index 5adc898ad6..0000000000 --- a/examples/jms/message-group2/src/main/resources/jndi.properties +++ /dev/null @@ -1,20 +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. - -java.naming.factory.initial=org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory -connectionFactory.ConnectionFactory=tcp://localhost:61616?groupID=Group-0 -queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/message-priority/pom.xml b/examples/jms/message-priority/pom.xml index 6956310388..b7a4d056b0 100644 --- a/examples/jms/message-priority/pom.xml +++ b/examples/jms/message-priority/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-message-priority-example + message-priority jar ActiveMQ Artemis JMS MessagePriorityExample Example @@ -37,71 +38,81 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.MessagePriorityExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-message-priority-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.MessagePriorityExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + message-priority + ${project.version} + + + + + diff --git a/examples/jms/message-priority/readme.html b/examples/jms/message-priority/readme.html index 96af7e24b3..9dd995c48b 100644 --- a/examples/jms/message-priority/readme.html +++ b/examples/jms/message-priority/readme.html @@ -27,22 +27,25 @@ under the License.

            JMS Message Priority Example

            +
            To run the example, simply type mvn verify from this directory, 
            or mvn -PnoServer verify if you want to start and create the server manually.
            + +

            This example shows how messages with different priorities are delivered in different orders.

            - +

            The Message Priority property carries the delivery preference of sent messages. It can be set by the message's standard header field 'JMSPriority' as defined in JMS specification version 1.1. The value is of type integer, ranging from 0 (the lowest) to 9 (the highest). When messages are being delivered, their priorities - will effect their order of delivery. Messages of higher priorities will likely be delivered before those - of lower priorities. Messages of equal priorities are delivered in the natural order of their arrival at + will effect their order of delivery. Messages of higher priorities will likely be delivered before those + of lower priorities. Messages of equal priorities are delivered in the natural order of their arrival at their destinations. Please consult the JMS 1.1 specification for full details.

            - +

            In this example, three messages are sent to a queue with different priorities. The first message is sent with default priority (4), the second is sent with a higher priority (5), and the third has the highest - priority (9). At the receiving end, we will show the order of receiving of the three messages. You will - see that the third message, though last sent, will 'jump' forward to be the first one received. The second + priority (9). At the receiving end, we will show the order of receiving of the three messages. You will + see that the third message, though last sent, will 'jump' forward to be the first one received. The second is also received ahead of the message first sent, but behind the third message. The first message, regardless of its being sent first, arrives last.

            - +

            Example step-by-step

            To run the example, simply type mvn verify -Pexample from this directory

            @@ -135,7 +138,7 @@ under the License. } - +
          14. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
          15. diff --git a/examples/jms/message-priority/src/main/java/org/apache/activemq/artemis/jms/example/MessagePriorityExample.java b/examples/jms/message-priority/src/main/java/org/apache/activemq/artemis/jms/example/MessagePriorityExample.java
            index 6435efe739..5f137feadd 100644
            --- a/examples/jms/message-priority/src/main/java/org/apache/activemq/artemis/jms/example/MessagePriorityExample.java
            +++ b/examples/jms/message-priority/src/main/java/org/apache/activemq/artemis/jms/example/MessagePriorityExample.java
            @@ -32,6 +32,9 @@ import javax.jms.Session;
             import javax.jms.TextMessage;
             import javax.naming.InitialContext;
             
            +import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
            +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
            +
             /**
              * A simple JMS example that shows the delivery order of messages with priorities.
              */
            @@ -42,17 +45,14 @@ public class MessagePriorityExample
                   AtomicBoolean result = new AtomicBoolean(true);
                   final ArrayList msgReceived = new ArrayList();
                   Connection connection = null;
            -      InitialContext initialContext = null;
                   try
                   {
            -         // Step 1. Create an initial context to perform the JNDI lookup.
            -         initialContext = new InitialContext();
             
                      // Step 2. look-up the JMS queue object from JNDI
            -         Queue queue = (Queue)initialContext.lookup("queue/exampleQueue");
            +         Queue queue = ActiveMQJMSClient.createQueue("exampleQueue");
             
                      // Step 3. look-up the JMS connection factory object from JNDI
            -         ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("ConnectionFactory");
            +         ConnectionFactory cf = new ActiveMQConnectionFactory();
             
                      // Step 4. Create a JMS Connection
                      connection = cf.createConnection();
            @@ -109,10 +109,6 @@ public class MessagePriorityExample
                   finally
                   {
                      // Step 13. Be sure to close our JMS resources!
            -         if (initialContext != null)
            -         {
            -            initialContext.close();
            -         }
                      if (connection != null)
                      {
                         connection.close();
            diff --git a/examples/jms/message-priority/src/main/resources/jndi.properties b/examples/jms/message-priority/src/main/resources/jndi.properties
            deleted file mode 100644
            index 93537c415a..0000000000
            --- a/examples/jms/message-priority/src/main/resources/jndi.properties
            +++ /dev/null
            @@ -1,20 +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.
            -
            -java.naming.factory.initial=org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory
            -connectionFactory.ConnectionFactory=tcp://localhost:61616
            -queue.queue/exampleQueue=exampleQueue
            diff --git a/examples/jms/multiple-failover-failback/pom.xml b/examples/jms/multiple-failover-failback/pom.xml
            index 4ae6e9edf9..c44a63fb39 100644
            --- a/examples/jms/multiple-failover-failback/pom.xml
            +++ b/examples/jms/multiple-failover-failback/pom.xml
            @@ -18,7 +18,8 @@ specific language governing permissions and limitations
             under the License.
             -->
             
            -
            +
                4.0.0
             
                
            @@ -27,7 +28,7 @@ under the License.
                   1.0.1-SNAPSHOT
                
             
            -   artemis-jms-multiple-failover-failback-example
            +   multiple-failover-failback
                jar
                ActiveMQ Artemis JMS Multiple Failover Failback Example
             
            @@ -47,79 +48,74 @@ under the License.
                   
                
             
            -   
            -      
            -         example
            -         
            -            
            -               
            -                  org.apache.activemq
            -                  artemis-maven-plugin
            -                  
            -                     
            -                        create0
            -                        
            -                           create
            -                        
            -                        
            -                           ${basedir}/target/server0
            -                           true
            -                           false
            -                           ../data
            -                           true
            -                        
            -                     
            -                     
            -                        create1
            -                        
            -                           create
            -                        
            -                        
            -                           ${basedir}/target/server1
            -                           true
            -                           true
            -                           ../data
            -                           true
            -                        
            -                     
            -                     
            -                        create2
            -                        
            -                           create
            -                        
            -                        
            -                           ${basedir}/target/server2
            -                           true
            -                           true
            -                           ../data
            -                        
            -                     
            -                     
            -                        runClient
            -                        
            -                           runClient
            -                        
            -                        
            -                           org.apache.activemq.artemis.jms.example.MultipleFailoverFailbackExample
            -                           
            -                              ${basedir}/target/server0
            -                              ${basedir}/target/server1
            -                              ${basedir}/target/server2
            -                           
            -                        
            -                     
            -                  
            -                  
            -                     
            -                        org.apache.activemq.examples.jms
            -                        artemis-jms-multiple-failover-failback-example
            -                        ${project.version}
            -                     
            -                  
            -                
            -            
            -         
            -      
            -   
            +   
            +      
            +         
            +            org.apache.activemq
            +            artemis-maven-plugin
            +            
            +               
            +                  create0
            +                  
            +                     create
            +                  
            +                  
            +                     ${basedir}/target/server0
            +                     true
            +                     false
            +                     ../data
            +                     true
            +                  
            +               
            +               
            +                  create1
            +                  
            +                     create
            +                  
            +                  
            +                     ${basedir}/target/server1
            +                     true
            +                     true
            +                     ../data
            +                     true
            +                  
            +               
            +               
            +                  create2
            +                  
            +                     create
            +                  
            +                  
            +                     ${basedir}/target/server2
            +                     true
            +                     true
            +                     ../data
            +                  
            +               
            +               
            +                  runClient
            +                  
            +                     runClient
            +                  
            +                  
            +                     org.apache.activemq.artemis.jms.example.MultipleFailoverFailbackExample
            +                     
            +                        ${basedir}/target/server0
            +                        ${basedir}/target/server1
            +                        ${basedir}/target/server2
            +                     
            +                  
            +               
            +            
            +            
            +               
            +                  org.apache.activemq.examples.jms
            +                  multiple-failover-failback
            +                  ${project.version}
            +               
            +            
            +         
            +      
            +   
             
             
            diff --git a/examples/jms/multiple-failover/pom.xml b/examples/jms/multiple-failover/pom.xml
            index cb00084618..3323ad5f66 100644
            --- a/examples/jms/multiple-failover/pom.xml
            +++ b/examples/jms/multiple-failover/pom.xml
            @@ -18,7 +18,8 @@ specific language governing permissions and limitations
             under the License.
             -->
             
            -
            +
                4.0.0
             
                
            @@ -27,7 +28,7 @@ under the License.
                   1.0.1-SNAPSHOT
                
             
            -   artemis-jms-multiple-failover-example
            +   multiple-failover
                jar
                ActiveMQ Artemis JMS Multiple Failover Example
             
            @@ -47,79 +48,74 @@ under the License.
                   
                
             
            -   
            -      
            -         example
            -         
            -            
            -               
            -                  org.apache.activemq
            -                  artemis-maven-plugin
            -                  
            -                     
            -                        create0
            -                        
            -                           create
            -                        
            -                        
            -                           ${basedir}/target/server0
            -                           true
            -                           false
            -                           ../data
            -                           true
            -                        
            -                     
            -                     
            -                        create1
            -                        
            -                           create
            -                        
            -                        
            -                           ${basedir}/target/server1
            -                           true
            -                           true
            -                           ../data
            -                           true
            -                        
            -                     
            -                     
            -                        create2
            -                        
            -                           create
            -                        
            -                        
            -                           ${basedir}/target/server2
            -                           true
            -                           true
            -                           ../data
            -                        
            -                     
            -                     
            -                        runClient
            -                        
            -                           runClient
            -                        
            -                        
            -                           org.apache.activemq.artemis.jms.example.MultipleFailoverExample
            -                           
            -                              ${basedir}/target/server0
            -                              ${basedir}/target/server1
            -                              ${basedir}/target/server2
            -                           
            -                        
            -                     
            -                  
            -                  
            -                     
            -                        org.apache.activemq.examples.jms
            -                        artemis-jms-multiple-failover-example
            -                        ${project.version}
            -                     
            -                  
            -               
            -            
            -         
            -      
            -   
            +   
            +      
            +         
            +            org.apache.activemq
            +            artemis-maven-plugin
            +            
            +               
            +                  create0
            +                  
            +                     create
            +                  
            +                  
            +                     ${basedir}/target/server0
            +                     true
            +                     false
            +                     ../data
            +                     true
            +                  
            +               
            +               
            +                  create1
            +                  
            +                     create
            +                  
            +                  
            +                     ${basedir}/target/server1
            +                     true
            +                     true
            +                     ../data
            +                     true
            +                  
            +               
            +               
            +                  create2
            +                  
            +                     create
            +                  
            +                  
            +                     ${basedir}/target/server2
            +                     true
            +                     true
            +                     ../data
            +                  
            +               
            +               
            +                  runClient
            +                  
            +                     runClient
            +                  
            +                  
            +                     org.apache.activemq.artemis.jms.example.MultipleFailoverExample
            +                     
            +                        ${basedir}/target/server0
            +                        ${basedir}/target/server1
            +                        ${basedir}/target/server2
            +                     
            +                  
            +               
            +            
            +            
            +               
            +                  org.apache.activemq.examples.jms
            +                  multiple-failover
            +                  ${project.version}
            +               
            +            
            +         
            +      
            +   
             
             
            diff --git a/examples/jms/no-consumer-buffering/pom.xml b/examples/jms/no-consumer-buffering/pom.xml
            index 19d91783d8..dcd0236552 100644
            --- a/examples/jms/no-consumer-buffering/pom.xml
            +++ b/examples/jms/no-consumer-buffering/pom.xml
            @@ -18,7 +18,8 @@ specific language governing permissions and limitations
             under the License.
             -->
             
            -
            +
                4.0.0
             
                
            @@ -27,7 +28,7 @@ under the License.
                   1.0.1-SNAPSHOT
                
             
            -   artemis-jms-no-consumer-buffering-example
            +   no-consumer-buffering
                jar
                ActiveMQ Artemis JMS No Consumer Buffering Example
             
            @@ -37,70 +38,80 @@ under the License.
             
                
                   
            -         org.apache.geronimo.specs
            -         geronimo-jms_2.0_spec
            +         org.apache.activemq
            +         artemis-jms-client
            +         ${project.version}
                   
                
             
                
                   
            -         example
            -         
            -            
            -               
            -                  org.apache.activemq
            -                  artemis-maven-plugin
            -                  
            -                     
            -                        create
            -                        
            -                           create
            -                        
            -                     
            -                     
            -                        start
            -                        
            -                           cli
            -                        
            -                        
            -                           true
            -                           tcp://localhost:61616
            -                           
            -                              run
            -                           
            -                        
            -                     
            -                     
            -                        runClient
            -                        
            -                           runClient
            -                        
            -                        
            -                           org.apache.activemq.artemis.jms.example.NoConsumerBufferingExample
            -                        
            -                     
            -                     
            -                        stop
            -                        
            -                           cli
            -                        
            -                        
            -                           
            -                              stop
            -                           
            -                        
            -                     
            -                  
            -                  
            -                     
            -                        org.apache.activemq.examples.jms
            -                        artemis-jms-no-consumer-buffering-example
            -                        ${project.version}
            -                     
            -                  
            -               
            -            
            -         
            +         
            +         noServer
            +         
            +            true
            +         
                   
                
            +   
            +      
            +         
            +            org.apache.activemq
            +            artemis-maven-plugin
            +            
            +               
            +                  create
            +                  
            +                     create
            +                  
            +                  
            +                     ${noServer}
            +                  
            +               
            +               
            +                  start
            +                  
            +                     cli
            +                  
            +                  
            +                     ${noServer}
            +                     true
            +                     tcp://localhost:61616
            +                     
            +                        run
            +                     
            +                  
            +               
            +               
            +                  runClient
            +                  
            +                     runClient
            +                  
            +                  
            +                     org.apache.activemq.artemis.jms.example.NoConsumerBufferingExample
            +                  
            +               
            +               
            +                  stop
            +                  
            +                     cli
            +                  
            +                  
            +                     ${noServer}
            +                     
            +                        stop
            +                     
            +                  
            +               
            +            
            +            
            +               
            +                  org.apache.activemq.examples.jms
            +                  no-consumer-buffering
            +                  ${project.version}
            +               
            +            
            +         
            +      
            +   
             
            diff --git a/examples/jms/no-consumer-buffering/readme.html b/examples/jms/no-consumer-buffering/readme.html
            index f05480b3e2..7f5e427dac 100644
            --- a/examples/jms/no-consumer-buffering/readme.html
            +++ b/examples/jms/no-consumer-buffering/readme.html
            @@ -27,6 +27,9 @@ under the License.
               
                  

            No Consumer Buffering Example

            +
            To run the example, simply type mvn verify from this directory, 
            or mvn -PnoServer verify if you want to start and create the server manually.
            + +

            By default, ActiveMQ Artemis consumers buffer messages from the server in a client side buffer before actual delivery actually occurs.

            This improves performance since otherwise every time you called receive() or had processed the last @@ -41,7 +44,7 @@ under the License.

            If orders were buffered in each consumer, and a new consumer was added that consumer would not be able to process orders which were already in the client side buffer of another consumer.

            To turn off client side buffering of messages, set consumer-window-size to zero.

            - +

            With ActiveMQ Artemis you can specify a maximum consume rate at which a JMS MessageConsumer will consume messages. This can be specified when creating or deploying the connection factory. See activemq-jms.xml

            Example step-by-step

            @@ -52,13 +55,13 @@ under the License. <connection-factory name="ConnectionFactory"> <connector-ref connector-name="netty-connector"/> <entries> - <entry name="ConnectionFactory"/> + <entry name="ConnectionFactory"/> </entries> - + <!-- We set the consumer window size to 0, which means messages are not buffered at all on the client side --> <consumer-window-size>0</consumer-window-size> - + </connection-factory>
            @@ -67,9 +70,7 @@ under the License.

            We then consume messages from each consumer in a semi-random order. We note that the messages are consumed in the order they were sent.

            If the messages had been buffered in each consumer they would not be available to be consumed - in an order determined afer delivery.

            - -

            To run the example, simply type mvn verify -Pexample from this directory

            + in an order determined afer delivery.

            1. Create an initial context to perform the JNDI lookup.
            2. @@ -106,74 +107,74 @@ under the License.
                          MessageConsumer consumer1 = session.createConsumer(queue);
                       
              - +
            3. Start the connection
            4. - +
                          
                    connection.start();
                          
                       
              - +
            5. Send 10 messages to the queue
            6.             
                    final int numMessages = 10;
              -         
              +
                    for (int i = 0; i < numMessages; i++)
                    {
                       TextMessage message = session.createTextMessage("This is text message: " + i);
               
                       producer.send(message);
              -     }           
              +     }
                          
                       
              - +
            7. Create another JMS MessageConsumer on the same queue.
            8.             MessageConsumer consumer2 = session.createConsumer(queue);
                       
              - +
            9. Consume three messages from consumer2
            10. - +
                          
                  for (int i = 0; i < 3; i++)
              -   {         
              +   {
                     TextMessage message = (TextMessage)consumer2.receive(2000);
              -            
              +
                     System.out.println("Consumed message from consumer2: " + message.getText());
              -   }    
              +   }
                          
                       
              - +
            11. Consume five messages from consumer1
            12. - +
                          
                  for (int i = 0; i < 5; i++)
              -   {         
              +   {
                     TextMessage message = (TextMessage)consumer1.receive(2000);
              -            
              +
                     System.out.println("Consumed message from consumer1: " + message.getText());
              -   }    
              +   }
                          
              -        
              - + +
            13. Consume two more messages from consumer2
            14. - +
                          
                  for (int i = 0; i < 2; i++)
              -   {         
              +   {
                     TextMessage message = (TextMessage)consumer1.receive(2000);
              -            
              +
                     System.out.println("Consumed message from consumer2: " + message.getText());
              -   }    
              +   }
                          
              -        
              - + +
            15. Be sure to close our resources!
            16. @@ -185,7 +186,7 @@ under the License. { initialContext.close(); } - + if (connection != null) { connection.close(); @@ -195,7 +196,7 @@ under the License.

            More information

            - + diff --git a/examples/jms/no-consumer-buffering/src/main/java/org/apache/activemq/artemis/jms/example/NoConsumerBufferingExample.java b/examples/jms/no-consumer-buffering/src/main/java/org/apache/activemq/artemis/jms/example/NoConsumerBufferingExample.java index 525a9c422c..c7fdf5618d 100644 --- a/examples/jms/no-consumer-buffering/src/main/java/org/apache/activemq/artemis/jms/example/NoConsumerBufferingExample.java +++ b/examples/jms/no-consumer-buffering/src/main/java/org/apache/activemq/artemis/jms/example/NoConsumerBufferingExample.java @@ -23,7 +23,9 @@ import javax.jms.MessageProducer; import javax.jms.Queue; import javax.jms.Session; import javax.jms.TextMessage; -import javax.naming.InitialContext; + +import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; /** * This example demonstrates how ActiveMQ Artemis consumers can be configured to not buffer any messages from @@ -34,17 +36,13 @@ public class NoConsumerBufferingExample public static void main(final String[] args) throws Exception { Connection connection = null; - InitialContext initialContext = null; try { - // Step 1. Create an initial context to perform the JNDI lookup. - initialContext = new InitialContext(); - // Step 2. Perfom a lookup on the queue - Queue queue = (Queue)initialContext.lookup("queue/exampleQueue"); + Queue queue = ActiveMQJMSClient.createQueue("exampleQueue"); - // Step 3. Perform a lookup on the Connection Factory - ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("ConnectionFactory"); + // Step 3. new Connection factory with consumerWindowsize=0 + ConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616?consumerWindowSize=0"); // Step 4. Create a JMS Connection connection = cf.createConnection(); @@ -110,10 +108,6 @@ public class NoConsumerBufferingExample finally { // Step 9. Be sure to close our resources! - if (initialContext != null) - { - initialContext.close(); - } if (connection != null) { diff --git a/examples/jms/non-transaction-failover/pom.xml b/examples/jms/non-transaction-failover/pom.xml index 72d463619b..6dec19e492 100644 --- a/examples/jms/non-transaction-failover/pom.xml +++ b/examples/jms/non-transaction-failover/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-non-transaction-failover-example + non-transaction-failover jar ActiveMQ Artemis JMS Non Transaction Failover Example @@ -42,71 +43,67 @@ under the License. ${project.version} - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - - - example - - - - org.apache.activemq - artemis-maven-plugin - - - create0 - - create - - - ${basedir}/target/server0 - true - false - ../data - true - - - - create1 - - create - - - ${basedir}/target/server1 - true - true - ../data - true - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.NonTransactionFailoverExample - - ${basedir}/target/server0 - ${basedir}/target/server1 - - - - - - - org.apache.activemq.examples.jms - artemis-jms-non-transaction-failover-example - ${project.version} - - - - - - - + + + + org.apache.activemq + artemis-maven-plugin + + + create0 + + create + + + ${basedir}/target/server0 + true + false + ../data + true + + + + create1 + + create + + + ${basedir}/target/server1 + true + true + ../data + true + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.NonTransactionFailoverExample + + ${basedir}/target/server0 + ${basedir}/target/server1 + + + + + + + org.apache.activemq.examples.jms + non-transaction-failover + ${project.version} + + + + + diff --git a/examples/jms/non-transaction-failover/readme.html b/examples/jms/non-transaction-failover/readme.html index 0e83d3733d..36672843af 100644 --- a/examples/jms/non-transaction-failover/readme.html +++ b/examples/jms/non-transaction-failover/readme.html @@ -26,11 +26,14 @@ under the License.

            JMS Failover Without Transactions Example

            - + +
            To run the example, simply type mvn verify from this directory.
            + +

            This example demonstrates two servers coupled as a live-backup pair for high availability (HA), and a client connection failing over from live to backup when the live server is crashed.

            Failover behavior differs whether the JMS session is transacted or not.

            -

            When a non-transacted JMS session is used, once and only once delivery is not guaranteed +

            When a non-transacted JMS session is used, once and only once delivery is not guaranteed and it is possible some messages will be lost or delivered twice, depending when the failover to the backup server occurs.

            It is up to the client to deal with such cases. To ensure once and only once delivery, the client must use transacted JMS sessions (as shown in the example for failover with transactions).

            @@ -38,7 +41,6 @@ under the License. section of the user manual.

            Example step-by-step

            -

            To run the example, simply type mvn verify -Pexample from this directory

            In this example, the live server is server 1, and the backup server is server 0

            The connection will initially be created to server1, server 1 will crash, and the client will carry on seamlessly on server 0, the backup server.

            @@ -58,12 +60,12 @@ under the License.
                        connection = connectionFactory.createConnection();
                     
            - +
          16. Create a JMS non-transacted Session with client acknowledgement
          17.             Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
                     
            - +
          18. Start the connection to ensure delivery occurs
          19.             connection.start();
            @@ -84,7 +86,7 @@ under the License.
                           System.out.println("Sent message: " + message.getText());
                        }
                     
            - +
          20. Receive and acknowledge half of the sent messages
          21.             TextMessage message0 = null;
            @@ -95,7 +97,7 @@ under the License.
                        }
                        message0.acknowledge();
                     
            - +
          22. Receive the second half of the sent messages but do not acknowledge them yet
          23.             for (int i = numMessages / 2; i < numMessages; i++)
            @@ -104,7 +106,7 @@ under the License.
                           System.out.println("Got message: " + message0.getText());
                        }
                     
            - +
          24. Crash server #1, the live server, and wait a little while to make sure it has really crashed.
          25.             killServer(1);
            @@ -122,7 +124,7 @@ under the License.
                           System.err.println("Got exception while acknowledging message: " + e.getMessage());
                        }
                     
            - +
          26. Consume again the second half of the messages againg. Note that they are not considered as redelivered
          27.             for (int i = numMessages / 2; i < numMessages; i++)
            @@ -132,7 +134,7 @@ under the License.
                        }
                        message0.acknowledge();
                     
            - +
          28. And finally, always remember to close your resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
          29. diff --git a/examples/jms/openwire/pom.xml b/examples/jms/openwire/pom.xml
            deleted file mode 100644
            index 3888f12e5f..0000000000
            --- a/examples/jms/openwire/pom.xml
            +++ /dev/null
            @@ -1,110 +0,0 @@
            -
            -
            -
            -
            -   4.0.0
            -
            -   
            -      org.apache.activemq.examples.jms
            -      jms-examples
            -      1.0.1-SNAPSHOT
            -   
            -
            -   artemis-jms-openwire-example
            -   jar
            -   ActiveMQ Artemis JMS Openwire Example
            -
            -   
            -      ${project.basedir}/../../..
            -   
            -
            -   
            -      
            -         org.apache.geronimo.specs
            -         geronimo-jms_2.0_spec
            -      
            -      
            -         org.apache.activemq
            -         activemq-client
            -      
            -   
            -
            -   
            -      
            -         example
            -         
            -            
            -               
            -                  org.apache.activemq
            -                  artemis-maven-plugin
            -                  
            -                     
            -                        create
            -                        
            -                           create
            -                        
            -                     
            -                     
            -                        start
            -                        
            -                           cli
            -                        
            -                        
            -                           true
            -                           tcp://localhost:61616
            -                           
            -                              run
            -                           
            -                        
            -                     
            -                     
            -                        runClient
            -                        
            -                           runClient
            -                        
            -                        
            -                           org.apache.activemq.artemis.jms.example.OpenWireExample
            -                        
            -                     
            -                     
            -                        stop
            -                        
            -                           cli
            -                        
            -                        
            -                           
            -                              stop
            -                           
            -                        
            -                     
            -                  
            -                  
            -                     
            -                        org.apache.activemq.examples.jms
            -                        artemis-jms-openwire-example
            -                        ${project.version}
            -                     
            -                  
            -               
            -            
            -         
            -      
            -   
            -
            diff --git a/examples/jms/openwire/readme.html b/examples/jms/openwire/readme.html
            deleted file mode 100644
            index df1e272e18..0000000000
            --- a/examples/jms/openwire/readme.html
            +++ /dev/null
            @@ -1,98 +0,0 @@
            -
            -
            -
            -  
            -    ActiveMQ Artemis OpenWire Example
            -    
            -    
            -    
            -  
            -  
            -     

            JMS OpenWire Example

            - -

            This example shows you how to configure ActiveMQ Artemis server to communicate with an ActiveMQ Artemis JMS client using ActiveMQ's native openwire protocol.

            - -

            Example step-by-step

            -

            To run the example, simply type mvn verify -Pexample from this directory

            - -
              -
            1. First we need to create an ActiveMQ Artemis connection factory.
            2. -
              -           ConnectionFactory factory = new ActiveMQConnectionFactory(urlString);
              -        
              - -
            3. Create the target queue
            4. -
              -           Queue queue = new ActiveMQQueue("exampleQueue");
              -        
              - -
            5. We create a JMS connection and start it
            6. -
              -           connection = cf.createConnection();
              -           connection.start()
              -        
              - -
            7. We create a JMS session. The session is created as non transacted and will auto acknowledge messages.
            8. -
              -           Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
              -        
              - -
            9. We create a JMS message producer on the session. This will be used to send the messages.
            10. -
              -          MessageProducer messageProducer = session.createProducer(topic);
              -       
              - -
            11. We create a JMS text message that we are going to send.
            12. -
              -           TextMessage message = session.createTextMessage("This is a text message");
              -        
              - -
            13. We send message to the queue
            14. -
              -           messageProducer.send(message);
              -        
              - -
            15. We create a JMS Message Consumer to receive the message.
            16. -
              -           MessageConsumer messageConsumer = session.createConsumer(queue);
              -        
              - -
            17. The message arrives at the consumer. In this case we use a timeout of 5000 milliseconds but we could use a blocking 'receive()'
            18. -
              -           TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
              -        
              - -
            19. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
            20. - -
              -           finally
              -           {
              -              if (connection != null)
              -              {
              -                 connection.close();
              -              }
              -           }
              -        
              - - - -
            - - diff --git a/examples/jms/openwire/src/main/java/org/apache/activemq/artemis/jms/example/OpenWireExample.java b/examples/jms/openwire/src/main/java/org/apache/activemq/artemis/jms/example/OpenWireExample.java deleted file mode 100644 index 202e1b0e8a..0000000000 --- a/examples/jms/openwire/src/main/java/org/apache/activemq/artemis/jms/example/OpenWireExample.java +++ /dev/null @@ -1,91 +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. - */ -package org.apache.activemq.artemis.jms.example; - -import javax.jms.Connection; -import javax.jms.ConnectionFactory; -import javax.jms.MessageConsumer; -import javax.jms.MessageProducer; -import javax.jms.Queue; -import javax.jms.Session; -import javax.jms.TextMessage; - -import org.apache.activemq.ActiveMQConnectionFactory; -import org.apache.activemq.command.ActiveMQQueue; - -import java.lang.Exception; - -/** - * A simple JMS Queue example that creates a producer and consumer on a queue - * and sends then receives a message. - */ -public class OpenWireExample -{ - public static final String OWHOST = "localhost"; - public static final int OWPORT = 61616; - - public static void main(final String[] args) throws Exception - { - Connection connection = null; - - try - { - String urlString = "tcp://" + OWHOST + ":" + OWPORT; - - // Step 1. Create an ActiveMQ Artemis Connection Factory - ConnectionFactory factory = new ActiveMQConnectionFactory(urlString); - - // Step 2. Create the target queue - Queue queue = new ActiveMQQueue("exampleQueue"); - - // Step 3. Create a JMS Connection - connection = factory.createConnection(); - - // Step 4. Start the Connection - connection.start(); - - // Step 5. Create a JMS Session - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - - // Step 6. Create a JMS Message Producer - MessageProducer producer = session.createProducer(queue); - - // Step 7. Create a Text Message - TextMessage message = session.createTextMessage("This is a text message"); - - // Step 8. Send the Message - producer.send(message); - - System.out.println("Sent message: " + message.getText()); - - // Step 9. Create a JMS Message Consumer - MessageConsumer messageConsumer = session.createConsumer(queue); - - // Step 10. Receive the message - TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000); - - System.out.println("Received message: " + messageReceived.getText()); - } - finally - { - if (connection != null) - { - connection.close(); - } - } - } -} diff --git a/examples/jms/openwire/src/main/resources/activemq/server0/artemis-roles.properties b/examples/jms/openwire/src/main/resources/activemq/server0/artemis-roles.properties deleted file mode 100644 index 4e2d44cec4..0000000000 --- a/examples/jms/openwire/src/main/resources/activemq/server0/artemis-roles.properties +++ /dev/null @@ -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 \ No newline at end of file diff --git a/examples/jms/openwire/src/main/resources/activemq/server0/artemis-users.properties b/examples/jms/openwire/src/main/resources/activemq/server0/artemis-users.properties deleted file mode 100644 index 4e2d44cec4..0000000000 --- a/examples/jms/openwire/src/main/resources/activemq/server0/artemis-users.properties +++ /dev/null @@ -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 \ No newline at end of file diff --git a/examples/jms/openwire/src/main/resources/activemq/server0/broker.xml b/examples/jms/openwire/src/main/resources/activemq/server0/broker.xml deleted file mode 100644 index c281c605b4..0000000000 --- a/examples/jms/openwire/src/main/resources/activemq/server0/broker.xml +++ /dev/null @@ -1,71 +0,0 @@ - - - - - - - - - - - - - ${data.dir}/server0/data/messaging/bindings - - ${data.dir}/server0/data/messaging/journal - - ${data.dir}/server0/data/messaging/largemessages - - ${data.dir}/server0/data/messaging/paging - - - tcp://localhost:61616 - - - - - - tcp://localhost:61616?protocols=OPENWIRE,CORE - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/jms/paging/pom.xml b/examples/jms/paging/pom.xml index 954aad947c..22c0c60755 100644 --- a/examples/jms/paging/pom.xml +++ b/examples/jms/paging/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-paging-example + paging jar ActiveMQ Artemis JMS Paging Example @@ -37,71 +38,81 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.PagingExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-paging-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.PagingExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + paging + ${project.version} + + + + + diff --git a/examples/jms/paging/readme.html b/examples/jms/paging/readme.html index 938d087e2d..1f9afd3816 100644 --- a/examples/jms/paging/readme.html +++ b/examples/jms/paging/readme.html @@ -27,17 +27,19 @@ under the License.

            Paging Example

            +
            To run the example, simply type mvn verify from this directory, 
            or mvn -PnoServer verify if you want to start and create the server manually.
            + +

            This example shows how ActiveMQ Artemis would avoid running out of memory resources by paging messages.

            A maxSize can be specified per Destination via the destinations settings configuration file (broker.xml).

            When messages routed to an address exceed the specified maxSize the server will begin to write messages to the file system, this is called paging. This will continue to occur until messages have been delivered to consumers and subsequently acknowledged freeing up memory. Messages will then be read from the file system , i.e. depaged, and routed as normal.

            Acknowledgement plays an important factor on paging as messages will stay on the file system until the memory is released - so it is important to make sure that the client acknowledges its messages.

            + so it is important to make sure that the client acknowledges its messages.

            Example step-by-step

            -

            To run the example, simply type mvn verify -Pexample from this directory

            1. First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the client-jndi.properties file in the directory ../common/config
            2. @@ -75,32 +77,32 @@ under the License.
              
                        MessageProducer pageMessageProducer = session.createProducer(pageQueue);
                        
              - +
            3. We don't need persistent messages in order to use paging. (This step is optional)
            4. 
                        pageMessageProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
                        
              - +
            5. Create a Binary Bytes Message with 10K arbitrary bytes
            6. 
                        BytesMessage message = session.createBytesMessage();
                        message.writeBytes(new byte[10 * 1024]);
                        
              - +
            7. Send only 20 messages to the Queue. This will be already enough for pagingQueue. Look at ./paging/config/activemq-queues.xml for the config.
            8. 
                        for (int i = 0; i < 20; i++)
                        {
                           pageMessageProducer.send(message);
              -         }         
              +         }
                        
              - +
            9. Create a JMS Message Producer
            10. 
                        MessageProducer messageProducer = session.createProducer(queue);
                        
              - +
            11. We don't need persistent messages in order to use paging. (This step is optional)
            12. 
                        messageProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
              @@ -115,26 +117,26 @@ under the License.
                        
            13. if you pause the example here, you will several files under ./build/data/paging
            14. - +
              
              -         // Thread.sleep(30000); // if you want to just our of curiosity, you can sleep here and inspect the created files just for 
              +         // Thread.sleep(30000); // if you want to just our of curiosity, you can sleep here and inspect the created files just for
                        
              - - + +
            15. Create a JMS Message Consumer
            16. 
                        MessageConsumer messageConsumer = session.createConsumer(queue);
                        
              - +
            17. Start the JMS Connection. This step will activate the subscribers to receive messages.
            18. 
                        connection.start();
                        
              - - + +
            19. Receive the messages. It's important to ACK for messages as ActiveMQ Artemis will not read messages from paging until messages are ACKed
            20. - +
              
                        for (int i = 0; i < 30000; i++)
                        {
              @@ -143,12 +145,12 @@ under the License.
                           if (i % 1000 == 0)
                           {
                              System.out.println("Received " + i + " messages");
              -               
              +
                              message.acknowledge();
                           }
                        }
                        
              - +
            21. Receive the messages from the Queue names pageQueue. Create the proper consumer for that.
            22. 
                        messageConsumer.close();
              @@ -157,7 +159,7 @@ under the License.
                        for (int i = 0; i < 20; i++)
                        {
                           message = (BytesMessage)messageConsumer.receive(1000);
              -            
              +
                           System.out.println("Received message " + i + " from pageQueue");
               
                           message.acknowledge();
              diff --git a/examples/jms/perf/pom.xml b/examples/jms/perf/pom.xml
              index b348a704ed..a1eb6ef2f9 100644
              --- a/examples/jms/perf/pom.xml
              +++ b/examples/jms/perf/pom.xml
              @@ -27,7 +27,7 @@ under the License.
                     1.0.1-SNAPSHOT
                  
               
              -   artemis-jms-perf-example
              +   perf
                  jar
                  ActiveMQ Artemis JMS PerfExample Example
               
              @@ -95,7 +95,7 @@ under the License.
                                    
                                       
                                          org.apache.activemq.examples.jms
              -                           artemis-jms-perf-example
              +                           perf
                                          ${project.version}
                                       
                                       
              diff --git a/examples/jms/pom.xml b/examples/jms/pom.xml
              index 4c8db041f7..3b59d1a7f9 100644
              --- a/examples/jms/pom.xml
              +++ b/examples/jms/pom.xml
              @@ -39,106 +39,8 @@ under the License.
               
                  
                     
              -         release
              -         
              -            aerogear
              -            application-layer-failover
              -            artemis-ra-rar
              -            bridge
              -            browser
              -            client-kickoff
              -            client-side-load-balancing
              -            client-side-failoverlistener
              -            clustered-durable-subscription
              -            clustered-grouping
              -            clustered-jgroups
              -            clustered-queue
              -            clustered-standalone
              -            clustered-static-oneway
              -            clustered-static-discovery
              -            clustered-topic
              -            colocated-failover
              -            colocated-failover-scale-down
              -            consumer-rate-limit
              -            dead-letter
              -            delayed-redelivery
              -            divert
              -            durable-subscription
              -            embedded
              -            embedded-simple
              -            expiry
              -            http-transport
              -            interceptor
              -            instantiate-connection-factory
              -            ha-policy-autobackup
              -            jms-auto-closeable
              -            jms-bridge
              -            jms-completion-listener
              -            jms-context
              -            jms-shared-consumer
              -            jmx
              -            large-message
              -            last-value-queue
              -            management
              -            management-notifications
              -            message-counters
              -            message-group
              -            message-group2
              -            message-priority
              -            multiple-failover
              -            multiple-failover-failback
              -            no-consumer-buffering
              -            non-transaction-failover
              -            openwire
              -            paging
              -            perf
              -            pre-acknowledge
              -            producer-rate-limit
              -            proton-cpp
              -            proton-j
              -            proton-ruby
              -            queue
              -            queue-message-redistribution
              -            queue-requestor
              -            queue-selector
              -            reattach-node
              -            rest
              -            replicated-failback
              -            replicated-failback-static
              -            replicated-multiple-failover
              -            replicated-transaction-failover
              -            request-reply
              -            scale-down
              -            scheduled-message
              -            security
              -            send-acknowledgements
              -            spring-integration
              -            ssl-enabled
              -            static-selector
              -            static-selector-jms
              -            stomp
              -            stomp-websockets
              -            stomp1.1
              -            stomp1.2
              -            stop-server-failover
              -            symmetric-cluster
              -            temp-queue
              -            topic
              -            topic-hierarchies
              -            topic-selector-example1
              -            topic-selector-example2
              -            transactional
              -            transaction-failover
              -            xa-heuristic
              -            xa-receive
              -            xa-send
              -         
              -      
              -      
              -         example
              -         
              -            true
              -         
              +         
              +         examples
                        
                           application-layer-failover
                           bridge
              @@ -150,12 +52,14 @@ under the License.
                           clustered-grouping
                           clustered-jgroups
                           clustered-queue
              -            clustered-standalone
                           clustered-static-oneway
                           clustered-static-discovery
                           clustered-topic
              +
              +            
              +
                           consumer-rate-limit
                           dead-letter
                           delayed-redelivery
              @@ -186,7 +90,6 @@ under the License.
                           multiple-failover-failback
                           no-consumer-buffering
                           non-transaction-failover
              -            openwire
                           paging
                           
                           
              @@ -200,8 +103,11 @@ under the License.
                           queue-requestor
                           queue-selector
                           reattach-node
              +
              +            
              +
                           replicated-multiple-failover
                           replicated-transaction-failover
                           request-reply
              @@ -211,9 +117,13 @@ under the License.
                           security
                           send-acknowledgements
                           spring-integration
              -            ssl-enabled
              +
              +            
              +
                           static-selector
              -            static-selector-jms
                           stomp
                           
                           
              diff --git a/examples/jms/pre-acknowledge/pom.xml b/examples/jms/pre-acknowledge/pom.xml
              index b181706838..e3ee5efb11 100644
              --- a/examples/jms/pre-acknowledge/pom.xml
              +++ b/examples/jms/pre-acknowledge/pom.xml
              @@ -18,7 +18,8 @@ specific language governing permissions and limitations
               under the License.
               -->
               
              -
              +
                  4.0.0
               
                  
              @@ -27,7 +28,7 @@ under the License.
                     1.0.1-SNAPSHOT
                  
               
              -   artemis-jms-pre-acknowledge-example
              +   pre-acknowledge
                  jar
                  ActiveMQ Artemis JMS Pre Acknowledge Example
               
              @@ -41,72 +42,77 @@ under the License.
                        artemis-jms-client
                        ${project.version}
                     
              -      
              -         org.apache.geronimo.specs
              -         geronimo-jms_2.0_spec
              -      
                  
               
                  
                     
              -         example
              -         
              -            
              -               
              -                  org.apache.activemq
              -                  artemis-maven-plugin
              -                  
              -                     
              -                        create
              -                        
              -                           create
              -                        
              -                     
              -                     
              -                        start
              -                        
              -                           cli
              -                        
              -                        
              -                           true
              -                           tcp://localhost:61616
              -                           
              -                              run
              -                           
              -                        
              -                     
              -                     
              -                        runClient
              -                        
              -                           runClient
              -                        
              -                        
              -                           org.apache.activemq.artemis.jms.example.PreacknowledgeExample
              -                        
              -                     
              -                     
              -                        stop
              -                        
              -                           cli
              -                        
              -                        
              -                           
              -                              stop
              -                           
              -                        
              -                     
              -                  
              -                  
              -                     
              -                        org.apache.activemq.examples.jms
              -                        artemis-jms-pre-acknowledge-example
              -                        ${project.version}
              -                     
              -                  
              -               
              -            
              -         
              +         
              +         noServer
              +         
              +            true
              +         
                     
                  
              +   
              +      
              +         
              +            org.apache.activemq
              +            artemis-maven-plugin
              +            
              +               
              +                  create
              +                  
              +                     create
              +                  
              +                  
              +                     ${noServer}
              +                  
              +               
              +               
              +                  start
              +                  
              +                     cli
              +                  
              +                  
              +                     ${noServer}
              +                     true
              +                     tcp://localhost:61616
              +                     
              +                        run
              +                     
              +                  
              +               
              +               
              +                  runClient
              +                  
              +                     runClient
              +                  
              +                  
              +                     org.apache.activemq.artemis.jms.example.PreacknowledgeExample
              +                  
              +               
              +               
              +                  stop
              +                  
              +                     cli
              +                  
              +                  
              +                     ${noServer}
              +                     
              +                        stop
              +                     
              +                  
              +               
              +            
              +            
              +               
              +                  org.apache.activemq.examples.jms
              +                  pre-acknowledge
              +                  ${project.version}
              +               
              +            
              +         
              +      
              +   
               
               
              diff --git a/examples/jms/pre-acknowledge/readme.html b/examples/jms/pre-acknowledge/readme.html
              index 893423ca8b..cadea2339c 100644
              --- a/examples/jms/pre-acknowledge/readme.html
              +++ b/examples/jms/pre-acknowledge/readme.html
              @@ -27,6 +27,9 @@ under the License.
                 
                    

              JMS Pre-Acknowledge Example

              +
              To run the example, simply type mvn verify from this directory, 
              or mvn -PnoServer verify if you want to start and create the server manually.
              + +

              Standard JMS supports three acknowledgement modes: AUTO_ACKNOWLEDGE, CLIENT_ACKNOWLEDGE, and DUPS_OK_ACKNOWLEDGE. For a full description on these modes please consult the JMS specification, or any JMS tutorial.

              @@ -44,9 +47,8 @@ under the License. update message will arrive soon, overriding the previous price.

              In order to use pre-acknowledge functionality with ActiveMQ Artemis the session has to be created with a special, ActiveMQ Artemis specific acknowledgement mode, given by the value of - ActiveMQJMSConstants.PRE_ACKNOWLEDGE. + ActiveMQJMSConstants.PRE_ACKNOWLEDGE.

              Example step-by-step

              -

              To run the example, simply type mvn verify -Pexample from this directory

              1. Create an initial context to perform the JNDI lookup.
              2. @@ -61,7 +63,7 @@ under the License. Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue"); - ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory"); + ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
              @@ -73,8 +75,8 @@ under the License. Session session = connection.createSession(false, ActiveMQSession.PRE_ACKNOWLEDGE); MessageProducer producer = session.createProducer(queue); - - MessageConsumer messageConsumer = session.createConsumer(queue); + + MessageConsumer messageConsumer = session.createConsumer(queue);
            @@ -85,7 +87,7 @@ under the License. producer.send(message1); - System.out.println("Sent message: " + message1.getText()); + System.out.println("Sent message: " + message1.getText()); @@ -94,8 +96,8 @@ under the License.
                        
                  int count = getMessageCount(connection);
            -       
            -     System.out.println("Queue message count is " + count);           
            +
            +     System.out.println("Queue message count is " + count);
                        
                     
            @@ -104,16 +106,16 @@ under the License. connection.start(); - Thread.sleep(1000); + Thread.sleep(1000);
          30. Print out the message count of the queue. It should now be zero, since the message has - already been acknowledged even before the consumer has received it.
          31. + already been acknowledged even before the consumer has received it.
                        
            -     count = getMessageCount(connection);         
            -     
            +     count = getMessageCount(connection);
            +
                  System.out.println("Queue message count is now " + count);
                        
                     
            @@ -123,7 +125,7 @@ under the License. TextMessage messageReceived = (TextMessage)messageConsumer.receive(5000); - System.out.println("Received message: " + messageReceived.getText()); + System.out.println("Received message: " + messageReceived.getText()); @@ -137,16 +139,16 @@ under the License. if (connection != null) { connection.close(); - } + }
          - +

          More information

          - + - + diff --git a/examples/jms/pre-acknowledge/src/main/java/org/apache/activemq/artemis/jms/example/PreacknowledgeExample.java b/examples/jms/pre-acknowledge/src/main/java/org/apache/activemq/artemis/jms/example/PreacknowledgeExample.java index 446cec0468..5191f85762 100644 --- a/examples/jms/pre-acknowledge/src/main/java/org/apache/activemq/artemis/jms/example/PreacknowledgeExample.java +++ b/examples/jms/pre-acknowledge/src/main/java/org/apache/activemq/artemis/jms/example/PreacknowledgeExample.java @@ -27,11 +27,11 @@ import javax.jms.QueueRequestor; import javax.jms.QueueSession; import javax.jms.Session; import javax.jms.TextMessage; -import javax.naming.InitialContext; import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; import org.apache.activemq.artemis.api.jms.ActiveMQJMSConstants; import org.apache.activemq.artemis.api.jms.management.JMSManagementHelper; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; /** * This example demonstrates the use of ActiveMQ Artemis "pre-acknowledge" functionality where @@ -44,17 +44,14 @@ public class PreacknowledgeExample public static void main(final String[] args) throws Exception { Connection connection = null; - - InitialContext initialContext = null; try { - // Step 1. Create an initial context to perform the JNDI lookup. - initialContext = new InitialContext(); - // Step 2. Perform the look-ups - Queue queue = (Queue)initialContext.lookup("queue/exampleQueue"); + // Step 2. instantiate the queue object + Queue queue = ActiveMQJMSClient.createQueue("exampleQueue"); - ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("ConnectionFactory"); + // new connection factory + ConnectionFactory cf = new ActiveMQConnectionFactory(); // Step 3. Create a the JMS objects connection = cf.createConnection(); @@ -102,10 +99,6 @@ public class PreacknowledgeExample finally { // Step 9. Be sure to close our resources! - if (initialContext != null) - { - initialContext.close(); - } if (connection != null) { connection.close(); diff --git a/examples/jms/producer-rate-limit/pom.xml b/examples/jms/producer-rate-limit/pom.xml index d407ea3a1b..c5145266c2 100644 --- a/examples/jms/producer-rate-limit/pom.xml +++ b/examples/jms/producer-rate-limit/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-producer-rate-limit-example + producer-rate-limit jar ActiveMQ Artemis JMS Producer Rate Limit Example @@ -37,71 +38,81 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.ProducerRateLimitExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-producer-rate-limit-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.ProducerRateLimitExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + producer-rate-limit + ${project.version} + + + + + diff --git a/examples/jms/producer-rate-limit/readme.html b/examples/jms/producer-rate-limit/readme.html index a2615ea41d..fa8d08679b 100644 --- a/examples/jms/producer-rate-limit/readme.html +++ b/examples/jms/producer-rate-limit/readme.html @@ -27,10 +27,13 @@ under the License.

          JMS Message Producer Rate Limiting

          +
          To run the example, simply type mvn verify from this directory, 
          or mvn -PnoServer verify if you want to start and create the server manually.
          + +

          With ActiveMQ Artemis you can specify a maximum send rate at which a JMS MessageProducer will send messages. This can be specified when creating or deploying the connection factory. See activemq-jms.xml

          If this value is specified then ActiveMQ Artemis will ensure that messages are never produced at a rate higher than - specified. This is a form of producer throttling.

          + specified. This is a form of producer throttling.

          Example step-by-step

          In this example we specify a producer-max-rate of 50 messages per second in the activemq-jms.xml file when deploying the connection factory:

          @@ -39,21 +42,19 @@ under the License. <connection-factory name="ConnectionFactory"> <connector-ref connector-name="netty-connector"/> <entries> - <entry name="ConnectionFactory"/> + <entry name="ConnectionFactory"/> </entries> - + <!-- We limit producers created on this connection factory to produce messages at a maximum rate of 50 messages per sec --> <producer-max-rate>50</producer-max-rate> - + </connection-factory>

          We then simply send as many messages as we can in 10 seconds and note how many messages are actually sent.

          We note that the number of messages sent per second never exceeds the specified value of 50 messages per second.

          -

          To run the example, simply type mvn verify -Pexample from this directory

          -
          1. Create an initial context to perform the JNDI lookup.
          2. @@ -107,13 +108,13 @@ under the License.
             
                     System.out.println("We sent " + i + " messages in " + (end - start) + " milliseconds");
             
            -        System.out.println("Actual send rate was " + rate + " messages per second");                      
            +        System.out.println("Actual send rate was " + rate + " messages per second");
                        
                     
            - +
          3. We note that the sending rate doesn't exceed 50 messages per second. Here's some example output from a real run
          4. - +
                        
                  [java] Will now send as many messages as we can in 10 seconds...
            @@ -121,7 +122,7 @@ under the License.
                  [java] Actual send rate was 49.64257347100874 messages per second
                        
                     
            - +
          5. For good measure we consumer the messages we produced.
          6. @@ -145,8 +146,8 @@ under the License.
                        i++;
                     }
             
            -        System.out.println("Received " + i + " messages");           
            -           
            +        System.out.println("Received " + i + " messages");
            +
                        
                     
            @@ -160,7 +161,7 @@ under the License. { initialContext.close(); } - + if (connection != null) { connection.close(); diff --git a/examples/jms/producer-rate-limit/src/main/java/org/apache/activemq/artemis/jms/example/ProducerRateLimitExample.java b/examples/jms/producer-rate-limit/src/main/java/org/apache/activemq/artemis/jms/example/ProducerRateLimitExample.java index c949122161..cfae82e729 100644 --- a/examples/jms/producer-rate-limit/src/main/java/org/apache/activemq/artemis/jms/example/ProducerRateLimitExample.java +++ b/examples/jms/producer-rate-limit/src/main/java/org/apache/activemq/artemis/jms/example/ProducerRateLimitExample.java @@ -23,7 +23,9 @@ import javax.jms.MessageProducer; import javax.jms.Queue; import javax.jms.Session; import javax.jms.TextMessage; -import javax.naming.InitialContext; + +import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; /** * This example demonstrates how a message producer can be limited to produce messages at a maximum rate @@ -34,17 +36,13 @@ public class ProducerRateLimitExample public static void main(final String[] args) throws Exception { Connection connection = null; - InitialContext initialContext = null; try { - // Step 1. Create an initial context to perform the JNDI lookup. - initialContext = new InitialContext(); - // Step 2. Perfom a lookup on the queue - Queue queue = (Queue)initialContext.lookup("queue/exampleQueue"); + Queue queue = ActiveMQJMSClient.createQueue("exampleQueue"); // Step 3. Perform a lookup on the Connection Factory - ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("ConnectionFactory"); + ConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616?producerMaxRate=50"); // Step 4. Create a JMS Connection connection = cf.createConnection(); @@ -106,10 +104,6 @@ public class ProducerRateLimitExample finally { // Step 9. Be sure to close our resources! - if (initialContext != null) - { - initialContext.close(); - } if (connection != null) { connection.close(); diff --git a/examples/jms/proton-cpp/pom.xml b/examples/jms/proton-cpp/pom.xml index 240667d032..32d2185dc3 100644 --- a/examples/jms/proton-cpp/pom.xml +++ b/examples/jms/proton-cpp/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-protoncpp + protoncpp jar ActiveMQ Artemis AMQP CPP Example @@ -49,64 +50,73 @@ under the License. - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.ProtonCPPExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-protoncpp - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.ProtonCPPExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + protoncpp + ${project.version} + + + + + diff --git a/examples/jms/proton-j/pom.xml b/examples/jms/proton-j/pom.xml index 2cdf0c823b..ebd92c44e2 100644 --- a/examples/jms/proton-j/pom.xml +++ b/examples/jms/proton-j/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-proton-j-example + artemis-proton-j jar ActiveMQ Artemis Proton-J Example @@ -45,64 +46,73 @@ under the License. - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.ProtonJExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-proton-j-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.ProtonJExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + artemis-proton-j + ${project.version} + + + + + diff --git a/examples/jms/proton-j/readme.html b/examples/jms/proton-j/readme.html index 7a5c88a975..fd77ffce52 100644 --- a/examples/jms/proton-j/readme.html +++ b/examples/jms/proton-j/readme.html @@ -27,6 +27,9 @@ under the License.

            Proton qpid java example

            +
            To run the example, simply type mvn verify from this directory, 
            or mvn -PnoServer verify if you want to start and create the server manually.
            + + <

            ActiveMQ Artemis is a multi protocol broker. It will inspect the initial handshake of clients to determine what protocol to use.

            All you need to do is to connect a client into activemq's configured port and you should be able connect.

            To run this example simply run the command mvn verify -Pexample, execute the compile.sh script and start the executable called ./hello

            diff --git a/examples/jms/proton-ruby/pom.xml b/examples/jms/proton-ruby/pom.xml index 54f2269e2c..6a90b8d956 100644 --- a/examples/jms/proton-ruby/pom.xml +++ b/examples/jms/proton-ruby/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-proton-ruby-example + proton-ruby jar ActiveMQ Artemis Proton Ruby Example @@ -35,37 +36,32 @@ under the License. ${project.basedir}/../../.. - - - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - ${basedir}/target/server0 - ${basedir}/target/classes/activemq/server0 - - - - - - org.apache.activemq.examples.jms - artemis-jms-proton-ruby-example - ${project.version} - - - - - - - + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${basedir}/target/server0 + ${basedir}/target/classes/activemq/server0 + + + + + + org.apache.activemq.examples.jms + proton-ruby + ${project.version} + + + + + diff --git a/examples/jms/proton-ruby/readme.html b/examples/jms/proton-ruby/readme.html index 951a654fd9..95c15b09b6 100644 --- a/examples/jms/proton-ruby/readme.html +++ b/examples/jms/proton-ruby/readme.html @@ -42,7 +42,7 @@ under the License.

            Example step-by-step

            -

            Firstly create the server by running the command mvn verify -Pexample

            +

            Firstly create the server by running the command mvn verify

            Start the server manually under ./target/server1/bin by calling ./artemis run

            Then in a separate window you can run the send ruby script by running the command ruby src/main/scripts/send.rb

            You can then receive the message via the receive ruby script by running ruby src/main/scripts/receive.rb

            diff --git a/examples/jms/queue-message-redistribution/pom.xml b/examples/jms/queue-message-redistribution/pom.xml index 8100fcc6cd..bee7116fdb 100644 --- a/examples/jms/queue-message-redistribution/pom.xml +++ b/examples/jms/queue-message-redistribution/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-queue-message-redistribution-example + queue-message-redistribution jar ActiveMQ Artemis JMS Queue Message Redistribution Example @@ -37,115 +38,127 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create0 - - create - - - ${basedir}/target/server0 - ${basedir}/target/classes/activemq/server0 - - - - create1 - - create - - - ${basedir}/target/server1 - ${basedir}/target/classes/activemq/server1 - - - - start0 - - cli - - - true - ${basedir}/target/server0 - tcp://localhost:61616 - - run - - server0 - - - - start1 - - cli - - - true - ${basedir}/target/server1 - tcp://localhost:61617 - - run - - server1 - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.QueueMessageRedistributionExample - - - - stop0 - - cli - - - ${basedir}/target/server0 - - stop - - - - - stop1 - - cli - - - ${basedir}/target/server1 - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-queue-message-redistribution-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create0 + + create + + + ${noServer} + ${basedir}/target/server0 + ${basedir}/target/classes/activemq/server0 + + + + create1 + + create + + + ${noServer} + ${basedir}/target/server1 + ${basedir}/target/classes/activemq/server1 + + + + start0 + + cli + + + ${noServer} + true + ${basedir}/target/server0 + tcp://localhost:61616 + + run + + server0 + + + + start1 + + cli + + + ${noServer} + true + ${basedir}/target/server1 + tcp://localhost:61617 + + run + + server1 + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.QueueMessageRedistributionExample + + + + + stop0 + + cli + + + ${noServer} + ${basedir}/target/server0 + + stop + + + + + stop1 + + cli + + + ${noServer} + ${basedir}/target/server1 + + stop + + + + + + + org.apache.activemq.examples.jms + queue-message-redistribution + ${project.version} + + + + + diff --git a/examples/jms/queue-message-redistribution/readme.html b/examples/jms/queue-message-redistribution/readme.html index 386e0466e1..b5c6cf6488 100644 --- a/examples/jms/queue-message-redistribution/readme.html +++ b/examples/jms/queue-message-redistribution/readme.html @@ -27,6 +27,9 @@ under the License.

            Message Redistribution Example

            +
            To run the example, simply type mvn verify from this directory, 
            or mvn -PnoServer verify if you want to start and create the server manually.
            + +

            This example demonstrates message redistribution between queues with the same name deployed in different nodes of a cluster.

            As demontrated in the clustered queue example, if queues with the same name are deployed on different nodes of @@ -41,7 +44,7 @@ under the License.

            Setting redistribution-delay to 0 will cause redistribution to occur immediately once there are no more matching consumers on a particular queue instance. Setting it to a positive value > 0 specifies a delay in milliseconds before attempting to redistribute. The delay is useful in the case that another consumer is - likely to be created on the queue, to avoid unnecessary redistribution.

            + likely to be created on the queue, to avoid unnecessary redistribution.

            Here's the relevant snippet from the activemq-queues.xml configuration, which tells the server to use a redistribution delay of 0 on any jms queues, i.e. any queues whose name starts with jms.

            @@ -51,194 +54,8 @@ under the License. <redistribution-delay>0</redistribution-delay> </address-setting> - +

            For more information on ActiveMQ Artemis load balancing, and clustering in general, please see the clustering - section of the user manual.

            -

            Example step-by-step

            -

            To run the example, simply type mvn verify -Pexample from this directory

            -
              -
            1. Get an initial context for looking up JNDI from server 0
            2. -
              -           
              -   ic0 = getContext(0);
              -   
              -        
              - -
            3. Look-up the JMS Queue object from JNDI
            4. -
              -           Queue queue = (Queue)ic0.lookup("/queue/exampleQueue");
              -        
              - -
            5. Look-up a JMS Connection Factory object from JNDI on server 0
            6. -
              -           ConnectionFactory cf0 = (ConnectionFactory)ic0.lookup("/ConnectionFactory");
              -        
              - -
            7. Get an initial context for looking up JNDI from server 1.
            8. -
              -           ic1 = getContext(1);
              -        
              - -
            9. Look-up a JMS Connection Factory object from JNDI on server 1
            10. -
              -           ConnectionFactory cf1 = (ConnectionFactory)ic1.lookup("/ConnectionFactory");
              -           
              -        
              - -
            11. We create a JMS Connection connection0 which is a connection to server 0
            12. -
              -          
              -   connection0 = cf0.createConnection();
              -          
              -        
              - -
            13. We create a JMS Connection connection1 which is a connection to server 1
            14. -
              -          
              -   connection1 = cf1.createConnection();
              -          
              -        
              - -
            15. We create a JMS Session on server 0, note the session is CLIENT_ACKNOWLEDGE
            16. -
              -           
              -   Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE);
              -           
              -        
              - -
            17. We create a JMS Session on server 1, note the session is CLIENT_ACKNOWLEDGE
            18. -
              -           
              -   Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
              -            
              -        
              - -
            19. We start the connections to ensure delivery occurs on them
            20. -
              -           
              -   connection0.start();
              -
              -   connection1.start();
              -           
              -        
              - -
            21. We create JMS MessageConsumer objects on server 0 and server 1
            22. -
              -           
              -   MessageConsumer consumer0 = session0.createConsumer(queue);
              -
              -   MessageConsumer consumer1 = session1.createConsumer(queue);
              -           
              -        
              - -
            23. We create a JMS MessageProducer object on server 0.
            24. -
              -           
              -   MessageProducer producer = session0.createProducer(queue);
              -        
              - -
            25. We send some messages to server 0.
            26. -
              -           
              -	final int numMessages = 10;
              -
              -	for (int i = 0; i < numMessages; i++)
              -	{
              -	   TextMessage message = session0.createTextMessage("This is text message " + i);
              -	      
              -	   producer.send(message);
              -	
              -	   System.out.println("Sent message: " + message.getText());
              -	}
              -           
              -        
              - -
            27. We now consume those messages on *both* server 0 and server 1. - We note the messages have been distributed between servers in a round robin fashion. - ActiveMQ Artemis has load balanced the messages between the available consumers on the different nodes. - ActiveMQ Artemis can be configured to always load balance messages to all nodes, or to only balance messages - to nodes which have consumers with no or matching selectors. See the user manual for more details.
            28. - JMS Queues implement point-to-point message where each message is only ever consumed by a - maximum of one consumer. -
              -           
              -	for (int i = 0; i < numMessages; i += 2)
              -	{
              -	   TextMessage message0 = (TextMessage)consumer0.receive(5000);
              -	
              -	   System.out.println("Got message: " + message0.getText() + " from node 0");
              -	
              -	   TextMessage message1 = (TextMessage)consumer1.receive(5000);
              -	
              -	   System.out.println("Got message: " + message1.getText() + " from node 1");
              -	}
              -           
              -        
              - -
            29. We acknowledge the messages consumed on node 0. The sessions are CLIENT_ACKNOWLEDGE so - messages will not get acknowledged until they are explicitly acknowledged. - Note that we do not acknowledge the message consumed on node 1 yet.
            30. -
              -           
              -           message0.acknowledge();
              -           
              -        
              - -
            31. We now close the session and consumer on node 1. (Closing the session automatically closes the consumer) -
            32. -
              -           session1.close();
              -        
              - -
            33. Since there is no more consumer on node 1, the messages on node 1 are now stranded (no local consumers) - so ActiveMQ Artemis will redistribute them to node 0 so they can be consumed. We consume them from - node 0.
            34. -
              -           
              -           for (int i = 0; i < numMessages; i += 2)
              -         {
              -            message0 = (TextMessage)consumer0.receive(5000);
              -
              -            System.out.println("Got message: " + message0.getText() + " from node 0");           
              -         }
              -           
              -        
              - -
            35. We ack the redistributed messages.
            36. -
              -           message0.acknowledge();
              -        
              - - -
            37. And finally (no pun intended), always remember to close your resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
            38. - -
              -           
              -	finally
              -	{
              -	      if (connection0 != null)
              -         {
              -            connection0.close();
              -         }
              -
              -         if (connection1 != null)
              -         {
              -            connection1.close();
              -         }
              -
              -         if (ic0 != null)
              -         {
              -            ic0.close();
              -         }
              -
              -         if (ic1 != null)
              -         {
              -            ic1.close();
              -         }
              -	}
              -           
              -        
              - -
            + section of the user manual.

            diff --git a/examples/jms/queue-message-redistribution/src/main/java/org/apache/activemq/artemis/jms/example/QueueMessageRedistributionExample.java b/examples/jms/queue-message-redistribution/src/main/java/org/apache/activemq/artemis/jms/example/QueueMessageRedistributionExample.java index aec56b1a10..f6cdb5eb9f 100644 --- a/examples/jms/queue-message-redistribution/src/main/java/org/apache/activemq/artemis/jms/example/QueueMessageRedistributionExample.java +++ b/examples/jms/queue-message-redistribution/src/main/java/org/apache/activemq/artemis/jms/example/QueueMessageRedistributionExample.java @@ -26,6 +26,9 @@ import javax.jms.TextMessage; import javax.naming.InitialContext; import java.util.Hashtable; +import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; + /** * This example demonstrates a queue with the same name deployed on two nodes of a cluster. * Messages are initially round robin'd between both nodes of the cluster. @@ -40,33 +43,16 @@ public class QueueMessageRedistributionExample Connection connection1 = null; - InitialContext ic0 = null; - - InitialContext ic1 = null; - try { - // Step 1. Get an initial context for looking up JNDI from server 0 - Hashtable properties = new Hashtable(); - properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); - properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61616"); - properties.put("queue.queue/exampleQueue", "exampleQueue"); - ic0 = new InitialContext(properties); - // Step 2. Look-up the JMS Queue object from JNDI - Queue queue = (Queue)ic0.lookup("queue/exampleQueue"); + Queue queue = ActiveMQJMSClient.createQueue("exampleQueue"); // Step 3. Look-up a JMS Connection Factory object from JNDI on server 0 - ConnectionFactory cf0 = (ConnectionFactory)ic0.lookup("ConnectionFactory"); - - // Step 4. Get an initial context for looking up JNDI from server 1 - properties = new Hashtable(); - properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); - properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61617"); - ic1 = new InitialContext(properties); + ConnectionFactory cf0 = new ActiveMQConnectionFactory("tcp://localhost:61616"); // Step 5. Look-up a JMS Connection Factory object from JNDI on server 1 - ConnectionFactory cf1 = (ConnectionFactory)ic1.lookup("ConnectionFactory"); + ConnectionFactory cf1 = new ActiveMQConnectionFactory("tcp://localhost:61617"); // Step 6. We create a JMS Connection connection0 which is a connection to server 0 connection0 = cf0.createConnection(); @@ -164,16 +150,6 @@ public class QueueMessageRedistributionExample { connection1.close(); } - - if (ic0 != null) - { - ic0.close(); - } - - if (ic1 != null) - { - ic1.close(); - } } } } diff --git a/examples/jms/queue-requestor/pom.xml b/examples/jms/queue-requestor/pom.xml index 2b8e16fca2..35c380ee3d 100644 --- a/examples/jms/queue-requestor/pom.xml +++ b/examples/jms/queue-requestor/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-queue-requestor-example + queue-requestor jar ActiveMQ Artemis JMS Queue Requestor Example @@ -37,71 +38,76 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.QueueRequestorExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-queue-requestor-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + + start + + cli + + + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.QueueRequestorExample + + + + stop + + cli + + + + stop + + + + + + + org.apache.activemq.examples.jms + queue-requestor + ${project.version} + + + + + diff --git a/examples/jms/queue-requestor/readme.html b/examples/jms/queue-requestor/readme.html index 416406a3bb..af11c9c87c 100644 --- a/examples/jms/queue-requestor/readme.html +++ b/examples/jms/queue-requestor/readme.html @@ -27,6 +27,9 @@ under the License.

            JMS QueueRequestor Example

            +
            To run the example, simply type mvn verify from this directory, 
            or mvn -PnoServer verify if you want to start and create the server manually.
            + +

            This example shows you how to use a QueueRequestor with ActiveMQ Artemis.

            JMS is mainly used to send messages asynchronously so that the producer of a message is not waiting for the result of the message consumption. However, there are cases where it is necessary to have a synchronous behavior: the code sending a message requires a reply for this message @@ -39,101 +42,5 @@ under the License.

            QueueRequestorExample
            A JMS Client which uses a QueueRequestor to send text requests to a queue and receive replies with the reversed text in a synchronous fashion
            - - -

            Example step-by-step

            -

            To run the example, simply type mvn verify -Pexample from this directory

            - -
              -
            1. First we need to get an initial context so we can look-up the JMS connection factory from JNDI. This initial context will get it's properties from the client-jndi.properties file in the directory ../common/config
            2. -
              -           InitialContext initialContext = getContext();
              -        
              - -
            3. We look up the JMS queue from JNDI
            4. -
              -           Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue");
              -        
              - -
            5. We look up JMS queue connection factory from JNDI
            6. -
              -           QueueConnectionFactory cf = (QueueConnectionFactory)initialContext.lookup("/ConnectionFactory");
              -        
              - -
            7. We create the TextReverserService which will consume messages from the queue
            8. -
              -            TextReverserService reverserService = new TextReverserService(cf, queue);
              -        
              - -
            9. We Create a JMS queue connection
            10. -
              -           connection = cf.createQueueConnection();
              -        
              - -
            11. We start the connection. In order for delivery to occur on any consumers or subscribers on a connection, the connection must be started
            12. -
              -           connection.start();
              -        
              - -
            13. We create a JMS queue session. The session is created as non transacted and will auto acknowledge messages (this is mandatory to use it to create a QueueRequestor)
            14. -
              -           QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
              -        
              - -
            15. We create a JMS QueueRequestor using the session and the queue
            16. -
              -           QueueRequestor queueRequestor = new QueueRequestor(session, queue);
              -        
              - -
            17. We create a JMS text message to send as a request
            18. -
              -           TextMessage request = session.createTextMessage("Hello, World!");
              -        
              - -
            19. We use the queue requestor to send the request and block until a reply is received.
              - Using the queue requestor simplify request/reply use case by abstracting boilerplate JMS code - (creating a temporary queue, a consumer and a producer, setting the JMS ReplyTo header on the request, - sending the request with the producer, consuming the message from the consumer). - All this code is replaced by a single call to QueueRequestor.request() method.

              -
            20. -
              -           TextMessage reply = (TextMessage)queueRequestor.request(request);
              -        
              - -
            21. The reply's text contains the reverse of the request's text
            22. -
              -           System.out.println("Send request: " + request.getText());
              -           System.out.println("Received reply:" + reply.getText());
              -        
              - -
            23. We close the queue requestor to release all the JMS resources it created to provide request/reply mechanism
            24. -
              -           queueRequestor.close()
              -        
              - -
            25. We do the same for the text reverser service
            26. -
              -           reverserService.close()
              -        
              - -
            27. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
            28. - -
              -           finally
              -           {
              -              if (initialContext != null)
              -              {
              -                initialContext.close();
              -              }
              -              if (connection != null)
              -              {
              -                 connection.close();
              -              }
              -           }
              -        
              - - - -
            diff --git a/examples/jms/queue-selector/pom.xml b/examples/jms/queue-selector/pom.xml index 7f179f60a0..dca32463f1 100644 --- a/examples/jms/queue-selector/pom.xml +++ b/examples/jms/queue-selector/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-queue-selector-example + queue-selector jar ActiveMQ Artemis JMS Queue Selector Example @@ -37,71 +38,81 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.QueueSelectorExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-queue-selector-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.QueueSelectorExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + queue-selector + ${project.version} + + + + + diff --git a/examples/jms/queue-selector/readme.html b/examples/jms/queue-selector/readme.html index 4af57ba152..edb3f7b503 100644 --- a/examples/jms/queue-selector/readme.html +++ b/examples/jms/queue-selector/readme.html @@ -27,139 +27,26 @@ under the License.

            JMS Queue Selector Example

            +
            To run the example, simply type mvn verify from this directory, 
            or mvn -PnoServer verify if you want to start and create the server manually.
            +

            This example shows you how to selectively consume messages using message selectors with queue consumers.

            - +

            Message selectors are strings with special syntax that can be used in creating consumers. Message consumers created with a message selector will only receive messages that match its selector. On message delivery, the JBoss Message Server evaluates the corresponding message headers of the messages against each selector, if any, and then delivers the 'matched' messages to its consumer. Please consult the JMS 1.1 specification for full details.

            - +

            In this example, three message consumers are created on a queue. The first consumer is created with selector 'color=red', it only receives messages that - have a 'color' string property of 'red' value; the second is created with selector 'color=green', it - only receives messages who have a 'color' string property of + have a 'color' string property of 'red' value; the second is created with selector 'color=green', it + only receives messages who have a 'color' string property of 'green' value; and the third without a selector, which means it receives all messages. To illustrate, three messages with different 'color' property values are created and sent.

            Selectors can be used with both queue consumers and topic consumers. The difference is that with queue consumers, a message is only delivered to one consumer on the queue, while topic consumers the message will be delivered to every - matching consumers. In this example, if the third consumer (anyConsumer) were the first consumer created, it will + matching consumers. In this example, if the third consumer (anyConsumer) were the first consumer created, it will consume the first message delivered, therefore there is no chance for the next consumer to get the message, even if it matches the selector.

            - - -

            Example step-by-step

            -

            To run the example, simply type mvn verify -Pexample from this directory

            - -
              -
            1. First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the client-jndi.properties file in the directory ../common/config
            2. -
              -           InitialContext initialContext = getContext();
              -        
              - -
            3. We look-up the JMS queue object from JNDI
            4. -
              -           Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");
              -        
              - -
            5. We look-up the JMS connection factory object from JNDI
            6. -
              -           ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
              -        
              - -
            7. We create a JMS connection
            8. -
              -           connection = cf.createConnection();
              -        
              - -
            9. We start the connection
            10. -
              -           connection.start();
              -        
              - -
            11. We create a JMS session. The session is created as non transacted and will auto acknowledge messages.
            12. -
              -           Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
              -        
              - -
            13. We create a JMS message producer on the session. This will be used to send the messages.
            14. -
              -          MessageProducer messageProducer = session.createProducer(queue);
              -       
              - -
            15. We create two selectors.
            16. -
              -           
              -           String redSelector = "color='red'";
              -           String greenSelector = "color='green'";
              -           
              -         
              - -
            17. We Create a JMS Message Consumer that receives 'red' messages.
            18. -
              -          
              -          MessageConsumer redConsumer = session.createConsumer(queue, redSelector);
              -          redConsumer.setMessageListener(new SimpleMessageListener("red"));
              -         
              -        
              - -
            19. We Create a second JMS Message Consumer that receives 'green' messages.
            20. -
              -          
              -          MessageConsumer greenConsumer = session.createConsumer(queue, greenSelector);
              -          greenConsumer.setMessageListener(new SimpleMessageListener("green"));
              -         
              -        
              - -
            21. We Create another JMS Message Consumer that receives all messages. Please not that the order - of consumers on a queue is of significance. If the anyConsumer is created before the above two, the - result will be totally different.
            22. -
              -          
              -          MessageConsumer anyConsumer = session.createConsumer(queue);
              -          anyConsumer.setMessageListener(new SimpleMessageListener("any"));
              -         
              -        
              - -
            23. We Create three messages, each has a different color property.
            24. -
              -           
              -           TextMessage redMessage = session.createTextMessage("Red");
              -           redMessage.setStringProperty("color", "red");
              -           TextMessage greenMessage = session.createTextMessage("Green");
              -           greenMessage.setStringProperty("color", "green");
              -           TextMessage blueMessage = session.createTextMessage("Blue");
              -           blueMessage.setStringProperty("color", "blue");
              -           
              -        
              - -
            25. We send the messages to the topic
            26. -
              -           
              -           producer.send(redMessage);
              -           System.out.println("Message sent: " + redMessage.getText());
              -           producer.send(greenMessage);
              -           System.out.println("Message sent: " + greenMessage.getText());
              -           producer.send(blueMessage);
              -           System.out.println("Message sent: " + blueMessage.getText());
              -           
              -        
              - -
            27. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
            28. - -
              -           finally
              -           {
              -              if (initialContext != null)
              -              {
              -                initialContext.close();
              -              }
              -              if (connection != null)
              -              {
              -                 connection.close();
              -              }
              -           }
              -        
              -
            diff --git a/examples/jms/queue/pom.xml b/examples/jms/queue/pom.xml index fecaaf78ba..ba5e182267 100644 --- a/examples/jms/queue/pom.xml +++ b/examples/jms/queue/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-queue-example + queue jar ActiveMQ Artemis JMS Queue Example @@ -37,71 +38,81 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.QueueExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-queue-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + + + start + + cli + + + true + ${noServer} + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.QueueExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + queue + ${project.version} + + + + + diff --git a/examples/jms/queue/readme.html b/examples/jms/queue/readme.html index a80d9739a2..71d4a9b801 100644 --- a/examples/jms/queue/readme.html +++ b/examples/jms/queue/readme.html @@ -27,88 +27,12 @@ under the License.

            JMS Queue Example

            +
            To run the example, simply type mvn verify from this directory, 
            or mvn -PnoServer verify if you want to start and create the server manually.
            + +

            This example shows you how to send and receive a message to a JMS Queue using ActiveMQ Artemis.

            Queues are a standard part of JMS, please consult the JMS 1.1 specification for full details.

            A Queue is used to send messages point to point, from a producer to a consumer. The queue guarantees message ordering between these 2 points.

            Notice this example is using pretty much a default stock configuration

            - -

            Example step-by-step

            -

            To run the example, simply type mvn verify -Pexample from this directory

            - -
              -
            1. First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the client-jndi.properties file in the directory ../common/config
            2. -
              -           InitialContext initialContext = getContext();
              -        
              - -
            3. We look-up the JMS queue object from JNDI
            4. -
              -           Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");
              -        
              - -
            5. We look-up the JMS connection factory object from JNDI
            6. -
              -           ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
              -        
              - -
            7. We create a JMS connection
            8. -
              -           connection = cf.createConnection();
              -        
              - -
            9. We create a JMS session. The session is created as non transacted and will auto acknowledge messages.
            10. -
              -           Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
              -        
              - -
            11. We create a JMS message producer on the session. This will be used to send the messages.
            12. -
              -          MessageProducer messageProducer = session.createProducer(topic);
              -       
              - -
            13. We create a JMS text message that we are going to send.
            14. -
              -           TextMessage message = session.createTextMessage("This is a text message");
              -        
              - -
            15. We send message to the queue
            16. -
              -           messageProducer.send(message);
              -        
              - -
            17. We create a JMS Message Consumer to receive the message.
            18. -
              -           MessageConsumer messageConsumer = session.createConsumer(queue);
              -        
              - -
            19. We start the connection. In order for delivery to occur on any consumers or subscribers on a connection, the connection must be started
            20. -
              -           connection.start();
              -        
              - -
            21. The message arrives at the consumer. In this case we use a timeout of 5000 milliseconds but we could use a blocking 'receive()'
            22. -
              -           TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
              -        
              - -
            23. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
            24. - -
              -           finally
              -           {
              -              if (initialContext != null)
              -              {
              -                initialContext.close();
              -              }
              -              if (connection != null)
              -              {
              -                 connection.close();
              -              }
              -           }
              -        
              - - - -
            diff --git a/examples/jms/reattach-node/pom.xml b/examples/jms/reattach-node/pom.xml index 885adcf528..cb0d5d373f 100644 --- a/examples/jms/reattach-node/pom.xml +++ b/examples/jms/reattach-node/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-reattach-node-example + reattach-node jar ActiveMQ Artemis JMS Reattach Node Example @@ -41,76 +42,79 @@ under the License. artemis-jms-client ${project.version} - - org.apache.geronimo.specs - geronimo-jms_2.0_spec - - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - ${basedir}/target/server0 - ${basedir}/target/classes/activemq/server0 - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.ReattachExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-reattach-node-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + ${basedir}/target/server0 + ${basedir}/target/classes/activemq/server0 + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.ReattachExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + reattach-node + ${project.version} + + + + + diff --git a/examples/jms/reattach-node/readme.html b/examples/jms/reattach-node/readme.html index 36fbfa23d7..3ed6a4af62 100644 --- a/examples/jms/reattach-node/readme.html +++ b/examples/jms/reattach-node/readme.html @@ -27,6 +27,9 @@ under the License.

            JMS Reattach Example

            +
            To run the example, simply type mvn verify from this directory, 
            or mvn -PnoServer verify if you want to start and create the server manually.
            + +

            This example demonstrates how ActiveMQ Artemis connections can be configured to be resilient to temporary network failures.

            In the case of a network failure being detected, either as a result of a failure to read/write to the connection, @@ -48,104 +51,5 @@ under the License.

            For more details on how to configure this and for clustering in general please consult the ActiveMQ Artemis user manual.

            - -

            Example step-by-step

            -

            To run the example, simply type mvn verify -Pexample from this directory

            - -
              -
            1. Create an initial context to perform the JNDI lookup.
            2. -
              -           initialContext = getContext(0);
              -        
              - -
            3. Perform a lookup on the queue
            4. -
              -           Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");
              -        
              - -
            5. Perform a lookup on the Connection Factory
            6. -
              -           ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
              -        
              - -
            7. We create a JMS connection
            8. -
              -           connection = cf.createConnection();
              -        
              - -
            9. We create a JMS session.
            10. -
              -           Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
              -        
              - -
            11. We create a JMS message producer.
            12. -
              -          MessageProducer messageProducer = session.createProducer(topic);
              -       
              - -
            13. We create a JMS text message that we are going to send.
            14. -
              -           TextMessage message = session.createTextMessage("This is a text message");
              -        
              - -
            15. We send message to the queue
            16. -
              -           messageProducer.send(message);
              -        
              - -
            17. We create a JMS Message Consumer to receive the message.
            18. -
              -           MessageConsumer messageConsumer = session.createConsumer(queue);
              -        
              - -
            19. We start the connection. In order for delivery to occur on any consumers or subscribers on a connection, the connection must be started
            20. -
              -           connection.start();
              -        
              - -
            21. To simulate a temporary problem on the network, we stop the remoting acceptor on the - server which will cause all client connections to fail.
            22. -
              -           stopAcceptor(initialContext);
              -        
              - -
            23. We wait 10 seconds, before restarting the acceptor. During this period the client will be retrying - to connect. When the acceptor is restarted it will be successful in reconnecting.
            24. - -
              -           
              -            Thread.sleep(10000);
              -
              -            startAcceptor(initialContext);
              -           
              -        
              - -
            25. We receive the message after reattachment! Note that no exceptions were received by the client.
            26. - -
              -           
              -           TextMessage messageReceived = (TextMessage)messageConsumer.receive(5000);
              -           
              -        
              - -
            27. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
            28. - -
              -           finally
              -           {
              -              if (initialContext != null)
              -              {
              -                initialContext.close();
              -              }
              -              if (connection != null)
              -              {
              -                 connection.close();
              -              }
              -           }
              -        
              - - - -
            diff --git a/examples/jms/reattach-node/src/main/java/org/apache/activemq/artemis/jms/example/ReattachExample.java b/examples/jms/reattach-node/src/main/java/org/apache/activemq/artemis/jms/example/ReattachExample.java index 2b05090b36..3a47fca307 100644 --- a/examples/jms/reattach-node/src/main/java/org/apache/activemq/artemis/jms/example/ReattachExample.java +++ b/examples/jms/reattach-node/src/main/java/org/apache/activemq/artemis/jms/example/ReattachExample.java @@ -16,8 +16,6 @@ */ package org.apache.activemq.artemis.jms.example; -import java.util.Hashtable; - import javax.jms.Connection; import javax.jms.ConnectionFactory; import javax.jms.Message; @@ -30,6 +28,7 @@ import javax.naming.InitialContext; import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; import org.apache.activemq.artemis.api.jms.management.JMSManagementHelper; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; /** * This examples demonstrates a connection created to a server. Failure of the network connection is then simulated @@ -127,11 +126,7 @@ public class ReattachExample // when the main connection has been stopped private static void stopStartAcceptor(final boolean stop) throws Exception { - Hashtable properties = new Hashtable(); - properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); - properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61617"); - InitialContext initialContext = new InitialContext(properties); - ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("ConnectionFactory"); + ConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61617"); Connection connection = null; try diff --git a/examples/jms/reattach-node/src/main/resources/activemq/server0/broker.xml b/examples/jms/reattach-node/src/main/resources/activemq/server0/broker.xml index 20321a2ba7..07e09bba6f 100644 --- a/examples/jms/reattach-node/src/main/resources/activemq/server0/broker.xml +++ b/examples/jms/reattach-node/src/main/resources/activemq/server0/broker.xml @@ -29,13 +29,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/replicated-failback-static/pom.xml b/examples/jms/replicated-failback-static/pom.xml index 2cd507255d..a19dec54c0 100644 --- a/examples/jms/replicated-failback-static/pom.xml +++ b/examples/jms/replicated-failback-static/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-replicated-failback-static-example + replicated-failback-static jar ActiveMQ Artemis JMS Replicated Failback Static Example @@ -42,66 +43,62 @@ under the License. ${project.version} - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - - - example - - - - org.apache.activemq - artemis-maven-plugin - - - create0 - - create - - - ${basedir}/target/server0 - ${basedir}/target/classes/activemq/server0 - -Dudp-address=${udp-address} - - - - create1 - - create - - - ${basedir}/target/server1 - ${basedir}/target/classes/activemq/server1 - -Dudp-address=${udp-address} - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.ReplicatedFailbackStaticExample - - ${basedir}/target/server0 - ${basedir}/target/server1 - - - - - - - org.apache.activemq.examples.jms - artemis-jms-replicated-failback-static-example - ${project.version} - - - - - - - + + + + org.apache.activemq + artemis-maven-plugin + + + create0 + + create + + + ${basedir}/target/server0 + ${basedir}/target/classes/activemq/server0 + -Dudp-address=${udp-address} + + + + create1 + + create + + + ${basedir}/target/server1 + ${basedir}/target/classes/activemq/server1 + -Dudp-address=${udp-address} + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.ReplicatedFailbackStaticExample + + ${basedir}/target/server0 + ${basedir}/target/server1 + + + + + + + org.apache.activemq.examples.jms + replicated-failback-static + ${project.version} + + + + + diff --git a/examples/jms/replicated-failback-static/readme.html b/examples/jms/replicated-failback-static/readme.html index 1dfb8b6537..a3cf6812cd 100644 --- a/examples/jms/replicated-failback-static/readme.html +++ b/examples/jms/replicated-failback-static/readme.html @@ -26,145 +26,13 @@ under the License.

            JMS Multiple Failover using Replication Example

            - + +
            To run the example, simply type mvn verify from this directory.
            +

            This example demonstrates three servers coupled as a live-backup-backup group for high availability (HA) using replication, and a client connection failing over from live to backup when the live server is crashed and then to the second backup once the new live fails.

            For more information on ActiveMQ Artemis failover and HA, and clustering in general, please see the clustering section of the user manual.

            - -

            Example step-by-step

            -

            To run the example, simply type mvn verify -Pexample from this directory

            -

            In this example, the live server is server 1, and the backup server is server 0

            -

            The connection will initially be created to server1, server 1 will crash, and the client will carry on - seamlessly on server 0, the backup server.

            - -
              -
            1. Get an initial context for looking up JNDI from server #0.
            2. -
              -           initialContext = getContext(0);
              -        
              - -
            3. Look up the JMS resources from JNDI on server #0.
            4. -
              -           Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue");
              -           ConnectionFactory connectionFactory = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
              -        
              - -
            5. Create a JMS Connection
            6. -
              -           connection = connectionFactory.createConnection();
              -        
              - -
            7. Create a client acknowledged Session
            8. -
              -           Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
              -        
              - -
            9. Start the connection to ensure delivery occurs
            10. -
              -           connection.start();
              -        
              - -
            11. Create a JMS MessageProducer
            12. -
              -           MessageProducer producer = session.createProducer(queue);
              -        
              - -
            13. Create a JMS MessageConsumer
            14. -
              -           MessageConsumer consumer = session.createConsumer(queue);
              -        
              - -
            15. Send some messages to server #0, the live server
            16. -
              -           for (int i = 0; i < numMessages; i++)
              -            {
              -                TextMessage message = session.createTextMessage("This is text message " + i);
              -                producer.send(message);
              -                System.out.println("Sent message: " + message.getText());
              -            }
              -        
              - -
            17. Receive and acknowledge a third of the sent messages
            18. -
              -           TextMessage message0 = null;
              -            for (int i = 0; i < numMessages / 3; i++)
              -            {
              -               message0 = (TextMessage)consumer.receive(5000);
              -               System.out.println("Got message: " + message0.getText());
              -            }
              -            message0.acknowledge();
              -        
              - -

              When server #0 crashes, the client automatically detects the failure and automatically - fails over from server #0 to server #1 (in your real program you wouldn't need to sleep). -

              - -
            19. Acknowledging the 2nd third of the sent messages will fail as failover to the backup server has occurred
            20. -
              -           try
              -             {
              -               message0.acknowledge();
              -            }
              -             catch (JMSException e)
              -            {
              -               System.err.println("Got exception while acknowledging message: " + e.getMessage());
              -            }
              -        
              - -
            21. Consume again the 2nd third of the messages again. Note that they are not considered as redelivered.
            22. -
              -           for (int i = numMessages / 3; i < (numMessages / 3) * 2; i++)
              -            {
              -              message0 = (TextMessage)consumer.receive(5000);
              -             System.out.printf("Got message: %s (redelivered?: %s)\n", message0.getText(), message0.getJMSRedelivered());
              -             }
              -         message0.acknowledge();
              -        
              - -

              now we Kill server #1 and wait for the server #2 to take over the responsibilities.

              - -
            23. Acknowledging the 3rd third of the sent messages will fail as failover to the backup server has occurred
            24. -
              -           try
              -            {
              -               message0.acknowledge();
              -           }
              -           catch (JMSException e)
              -          {
              -                System.err.println("Got exception while acknowledging message: " + e.getMessage());
              -             }
              -        
              - - -
            25. Consume again the 3rd third of the messages again. Note that they are not considered as redelivered
            26. -
              -            for (int i = (numMessages / 3) * 2; i < numMessages; i++)
              -             {
              -               message0 = (TextMessage)consumer.receive(5000);
              -               System.out.printf("Got message: %s (redelivered?: %s)\n", message0.getText(), message0.getJMSRedelivered());
              -            }
              -             message0.acknowledge();
              -        
              - -
            27. And finally, always remember to close your resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
            28. - -
              -           finally
              -           {
              -              if (connection != null)
              -              {
              -                 connection.close();
              -              }
              -
              -              if (initialContext != null)
              -              {
              -                 initialContext.close();
              -              }
              -           }
              -        
              - -
            diff --git a/examples/jms/replicated-failback-static/src/main/resources/activemq/server0/broker.xml b/examples/jms/replicated-failback-static/src/main/resources/activemq/server0/broker.xml index f59bdbcd82..f6fa349a9b 100644 --- a/examples/jms/replicated-failback-static/src/main/resources/activemq/server0/broker.xml +++ b/examples/jms/replicated-failback-static/src/main/resources/activemq/server0/broker.xml @@ -29,13 +29,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging exampleUser diff --git a/examples/jms/replicated-failback-static/src/main/resources/activemq/server1/broker.xml b/examples/jms/replicated-failback-static/src/main/resources/activemq/server1/broker.xml index 9173c64a41..9b89d8089d 100644 --- a/examples/jms/replicated-failback-static/src/main/resources/activemq/server1/broker.xml +++ b/examples/jms/replicated-failback-static/src/main/resources/activemq/server1/broker.xml @@ -29,13 +29,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging exampleUser diff --git a/examples/jms/replicated-failback/pom.xml b/examples/jms/replicated-failback/pom.xml index d9c5150a8b..9cfdbc5e82 100644 --- a/examples/jms/replicated-failback/pom.xml +++ b/examples/jms/replicated-failback/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-replicated-failback-example + replicated-failback jar ActiveMQ Artemis JMS Replicated Failback Example @@ -47,61 +48,56 @@ under the License. - - - example - - - - org.apache.activemq - artemis-maven-plugin - - - create0 - - create - - - ${basedir}/target/server0 - ${basedir}/target/classes/activemq/server0 - -Dudp-address=${udp-address} - - - - create1 - - create - - - ${basedir}/target/server1 - ${basedir}/target/classes/activemq/server1 - -Dudp-address=${udp-address} - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.ReplicatedFailbackExample - - ${basedir}/target/server0 - ${basedir}/target/server1 - - - - - - - org.apache.activemq.examples.jms - artemis-jms-replicated-failback-example - ${project.version} - - - - - - - + + + + org.apache.activemq + artemis-maven-plugin + + + create0 + + create + + + ${basedir}/target/server0 + ${basedir}/target/classes/activemq/server0 + -Dudp-address=${udp-address} + + + + create1 + + create + + + ${basedir}/target/server1 + ${basedir}/target/classes/activemq/server1 + -Dudp-address=${udp-address} + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.ReplicatedFailbackExample + + ${basedir}/target/server0 + ${basedir}/target/server1 + + + + + + + org.apache.activemq.examples.jms + replicated-failback + ${project.version} + + + + + diff --git a/examples/jms/replicated-failback/readme.html b/examples/jms/replicated-failback/readme.html index c42eaa17f7..aaf90eb7b5 100644 --- a/examples/jms/replicated-failback/readme.html +++ b/examples/jms/replicated-failback/readme.html @@ -27,146 +27,12 @@ under the License.

            JMS Multiple Failover using Replication Example

            - Note that failback example is not working in 2.3.0.Alpha but will be fully functional in the next release. - +
            To run the example, simply type mvn verify from this directory.
            +

            This example demonstrates three servers coupled as a live-backup-backup group for high availability (HA) using replication, and a client connection failing over from live to backup when the live server is crashed and then to the second backup once the new live fails.

            For more information on ActiveMQ Artemis failover and HA, and clustering in general, please see the clustering section of the user manual.

            - -

            Example step-by-step

            -

            To run the example, simply type mvn verify -Pexample from this directory

            -

            In this example, the live server is server 1, and the backup server is server 0

            -

            The connection will initially be created to server1, server 1 will crash, and the client will carry on - seamlessly on server 0, the backup server.

            - -
              -
            1. Get an initial context for looking up JNDI from server #0.
            2. -
              -           initialContext = getContext(0);
              -        
              - -
            3. Look up the JMS resources from JNDI on server #0.
            4. -
              -           Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue");
              -           ConnectionFactory connectionFactory = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
              -        
              - -
            5. Create a JMS Connection
            6. -
              -           connection = connectionFactory.createConnection();
              -        
              - -
            7. Create a client acknowledged Session
            8. -
              -           Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
              -        
              - -
            9. Start the connection to ensure delivery occurs
            10. -
              -           connection.start();
              -        
              - -
            11. Create a JMS MessageProducer
            12. -
              -           MessageProducer producer = session.createProducer(queue);
              -        
              - -
            13. Create a JMS MessageConsumer
            14. -
              -           MessageConsumer consumer = session.createConsumer(queue);
              -        
              - -
            15. Send some messages to server #0, the live server
            16. -
              -           for (int i = 0; i < numMessages; i++)
              -            {
              -                TextMessage message = session.createTextMessage("This is text message " + i);
              -                producer.send(message);
              -                System.out.println("Sent message: " + message.getText());
              -            }
              -        
              - -
            17. Receive and acknowledge a third of the sent messages
            18. -
              -           TextMessage message0 = null;
              -            for (int i = 0; i < numMessages / 3; i++)
              -            {
              -               message0 = (TextMessage)consumer.receive(5000);
              -               System.out.println("Got message: " + message0.getText());
              -            }
              -            message0.acknowledge();
              -        
              - -

              When server #0 crashes, the client automatically detects the failure and automatically - fails over from server #0 to server #1 (in your real program you wouldn't need to sleep). -

              - -
            19. Acknowledging the 2nd third of the sent messages will fail as failover to the backup server has occurred
            20. -
              -           try
              -             {
              -               message0.acknowledge();
              -            }
              -             catch (JMSException e)
              -            {
              -               System.err.println("Got exception while acknowledging message: " + e.getMessage());
              -            }
              -        
              - -
            21. Consume again the 2nd third of the messages again. Note that they are not considered as redelivered.
            22. -
              -           for (int i = numMessages / 3; i < (numMessages / 3) * 2; i++)
              -            {
              -              message0 = (TextMessage)consumer.receive(5000);
              -             System.out.printf("Got message: %s (redelivered?: %s)\n", message0.getText(), message0.getJMSRedelivered());
              -             }
              -         message0.acknowledge();
              -        
              - -

              now we Kill server #1 and wait for the server #2 to take over the responsibilities.

              - -
            23. Acknowledging the 3rd third of the sent messages will fail as failover to the backup server has occurred
            24. -
              -           try
              -            {
              -               message0.acknowledge();
              -           }
              -           catch (JMSException e)
              -          {
              -                System.err.println("Got exception while acknowledging message: " + e.getMessage());
              -             }
              -        
              - - -
            25. Consume again the 3rd third of the messages again. Note that they are not considered as redelivered
            26. -
              -            for (int i = (numMessages / 3) * 2; i < numMessages; i++)
              -             {
              -               message0 = (TextMessage)consumer.receive(5000);
              -               System.out.printf("Got message: %s (redelivered?: %s)\n", message0.getText(), message0.getJMSRedelivered());
              -            }
              -             message0.acknowledge();
              -        
              - -
            27. And finally, always remember to close your resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
            28. - -
              -           finally
              -           {
              -              if (connection != null)
              -              {
              -                 connection.close();
              -              }
              -
              -              if (initialContext != null)
              -              {
              -                 initialContext.close();
              -              }
              -           }
              -        
              - -
            diff --git a/examples/jms/replicated-failback/src/main/resources/activemq/server0/broker.xml b/examples/jms/replicated-failback/src/main/resources/activemq/server0/broker.xml index ab85a389cd..c7f47839ec 100644 --- a/examples/jms/replicated-failback/src/main/resources/activemq/server0/broker.xml +++ b/examples/jms/replicated-failback/src/main/resources/activemq/server0/broker.xml @@ -29,13 +29,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging exampleUser diff --git a/examples/jms/replicated-failback/src/main/resources/activemq/server1/broker.xml b/examples/jms/replicated-failback/src/main/resources/activemq/server1/broker.xml index cfb7e3322f..da5a656401 100644 --- a/examples/jms/replicated-failback/src/main/resources/activemq/server1/broker.xml +++ b/examples/jms/replicated-failback/src/main/resources/activemq/server1/broker.xml @@ -29,13 +29,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging exampleUser diff --git a/examples/jms/replicated-multiple-failover/pom.xml b/examples/jms/replicated-multiple-failover/pom.xml index d1af812756..bd9a44cf23 100644 --- a/examples/jms/replicated-multiple-failover/pom.xml +++ b/examples/jms/replicated-multiple-failover/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-replicated-multiple-failover-example + replicated-multiple-failover jar ActiveMQ Artemis JMS Replicated Multiple Failover Example @@ -42,79 +43,76 @@ under the License. ${project.version} - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - - - example - - - - org.apache.activemq - artemis-maven-plugin - - - create0 - - create - - - ${basedir}/target/server0 - ${basedir}/target/classes/activemq/server0 - -Dudp-address=${udp-address} - - - - create1 - - create - - - ${basedir}/target/server1 - ${basedir}/target/classes/activemq/server1 - -Dudp-address=${udp-address} - - - - create2 - - create - - - ${basedir}/target/server2 - ${basedir}/target/classes/activemq/server2 - -Dudp-address=${udp-address} - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.ReplicatedMultipleFailoverExample - - ${basedir}/target/server0 - ${basedir}/target/server1 - ${basedir}/target/server2 - - - - - - - org.apache.activemq.examples.jms - artemis-jms-replicated-multiple-failover-example - ${project.version} - - - - - - - + + + + org.apache.activemq + artemis-maven-plugin + + + create0 + + create + + + ${basedir}/target/server0 + ${basedir}/target/classes/activemq/server0 + -Dudp-address=${udp-address} + + + + create1 + + create + + + ${basedir}/target/server1 + ${basedir}/target/classes/activemq/server1 + -Dudp-address=${udp-address} + + + + create2 + + create + + + ${basedir}/target/server2 + ${basedir}/target/classes/activemq/server2 + -Dudp-address=${udp-address} + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.ReplicatedMultipleFailoverExample + + + ${basedir}/target/server0 + ${basedir}/target/server1 + ${basedir}/target/server2 + + + + + + + org.apache.activemq.examples.jms + replicated-multiple-failover + ${project.version} + + + + + diff --git a/examples/jms/replicated-multiple-failover/readme.html b/examples/jms/replicated-multiple-failover/readme.html index d852f8f99f..63ec95f5a4 100644 --- a/examples/jms/replicated-multiple-failover/readme.html +++ b/examples/jms/replicated-multiple-failover/readme.html @@ -26,7 +26,10 @@ under the License.

            JMS Multiple Failover using Replication Example

            - + +
            To run the example, simply type mvn verify from this directory.
            + +

            This example demonstrates three servers coupled as a live-backup-backup group for high availability (HA) using replication, and a client connection failing over from live to backup when the live server is crashed and then to the second backup once the new live fails.

            @@ -38,133 +41,5 @@ under the License.

            In this example, the live server is server 1, and the backup server is server 0

            The connection will initially be created to server1, server 1 will crash, and the client will carry on seamlessly on server 0, the backup server.

            - -
              -
            1. Get an initial context for looking up JNDI from server #0.
            2. -
              -           initialContext = getContext(0);
              -        
              - -
            3. Look up the JMS resources from JNDI on server #0.
            4. -
              -           Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue");
              -           ConnectionFactory connectionFactory = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
              -        
              - -
            5. Create a JMS Connection
            6. -
              -           connection = connectionFactory.createConnection();
              -        
              - -
            7. Create a client acknowledged Session
            8. -
              -           Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
              -        
              - -
            9. Start the connection to ensure delivery occurs
            10. -
              -           connection.start();
              -        
              - -
            11. Create a JMS MessageProducer
            12. -
              -           MessageProducer producer = session.createProducer(queue);
              -        
              - -
            13. Create a JMS MessageConsumer
            14. -
              -           MessageConsumer consumer = session.createConsumer(queue);
              -        
              - -
            15. Send some messages to server #0, the live server
            16. -
              -           for (int i = 0; i < numMessages; i++)
              -            {
              -                TextMessage message = session.createTextMessage("This is text message " + i);
              -                producer.send(message);
              -                System.out.println("Sent message: " + message.getText());
              -            }
              -        
              - -
            17. Receive and acknowledge a third of the sent messages
            18. -
              -           TextMessage message0 = null;
              -            for (int i = 0; i < numMessages / 3; i++)
              -            {
              -               message0 = (TextMessage)consumer.receive(5000);
              -               System.out.println("Got message: " + message0.getText());
              -            }
              -            message0.acknowledge();
              -        
              - -

              When server #0 crashes, the client automatically detects the failure and automatically - fails over from server #0 to server #1 (in your real program you wouldn't need to sleep). -

              - -
            19. Acknowledging the 2nd third of the sent messages will fail as failover to the backup server has occurred
            20. -
              -           try
              -             {
              -               message0.acknowledge();
              -            }
              -             catch (JMSException e)
              -            {
              -               System.err.println("Got exception while acknowledging message: " + e.getMessage());
              -            }
              -        
              - -
            21. Consume again the 2nd third of the messages again. Note that they are not considered as redelivered.
            22. -
              -           for (int i = numMessages / 3; i < (numMessages / 3) * 2; i++)
              -            {
              -              message0 = (TextMessage)consumer.receive(5000);
              -             System.out.printf("Got message: %s (redelivered?: %s)\n", message0.getText(), message0.getJMSRedelivered());
              -             }
              -         message0.acknowledge();
              -        
              - -

              now we Kill server #1 and wait for the server #2 to take over the responsibilities.

              - -
            23. Acknowledging the 3rd third of the sent messages will fail as failover to the backup server has occurred
            24. -
              -           try
              -            {
              -               message0.acknowledge();
              -           }
              -           catch (JMSException e)
              -          {
              -                System.err.println("Got exception while acknowledging message: " + e.getMessage());
              -             }
              -        
              - - -
            25. Consume again the 3rd third of the messages again. Note that they are not considered as redelivered
            26. -
              -            for (int i = (numMessages / 3) * 2; i < numMessages; i++)
              -             {
              -               message0 = (TextMessage)consumer.receive(5000);
              -               System.out.printf("Got message: %s (redelivered?: %s)\n", message0.getText(), message0.getJMSRedelivered());
              -            }
              -             message0.acknowledge();
              -        
              - -
            27. And finally, always remember to close your resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
            28. - -
              -           finally
              -           {
              -              if (connection != null)
              -              {
              -                 connection.close();
              -              }
              -
              -              if (initialContext != null)
              -              {
              -                 initialContext.close();
              -              }
              -           }
              -        
              - -
            diff --git a/examples/jms/replicated-multiple-failover/src/main/resources/activemq/server0/broker.xml b/examples/jms/replicated-multiple-failover/src/main/resources/activemq/server0/broker.xml index fb321c22fc..43f16938fc 100644 --- a/examples/jms/replicated-multiple-failover/src/main/resources/activemq/server0/broker.xml +++ b/examples/jms/replicated-multiple-failover/src/main/resources/activemq/server0/broker.xml @@ -29,13 +29,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/replicated-multiple-failover/src/main/resources/activemq/server1/broker.xml b/examples/jms/replicated-multiple-failover/src/main/resources/activemq/server1/broker.xml index 1cb959ce8f..7f17fb8a94 100644 --- a/examples/jms/replicated-multiple-failover/src/main/resources/activemq/server1/broker.xml +++ b/examples/jms/replicated-multiple-failover/src/main/resources/activemq/server1/broker.xml @@ -29,13 +29,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/replicated-multiple-failover/src/main/resources/activemq/server2/broker.xml b/examples/jms/replicated-multiple-failover/src/main/resources/activemq/server2/broker.xml index fbbd45f9dd..c5f06cc254 100644 --- a/examples/jms/replicated-multiple-failover/src/main/resources/activemq/server2/broker.xml +++ b/examples/jms/replicated-multiple-failover/src/main/resources/activemq/server2/broker.xml @@ -29,13 +29,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/replicated-transaction-failover/pom.xml b/examples/jms/replicated-transaction-failover/pom.xml index 2c10c66ce0..437404c34e 100644 --- a/examples/jms/replicated-transaction-failover/pom.xml +++ b/examples/jms/replicated-transaction-failover/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-replicated-transaction-failover-example + replicated-transaction-failover jar ActiveMQ Artemis JMS Replicated Transaction Failover Example @@ -42,66 +43,62 @@ under the License. ${project.version} - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - - - - example - - - - org.apache.activemq - artemis-maven-plugin - - - create0 - - create - - - ${basedir}/target/server0 - ${basedir}/target/classes/activemq/server0 - -Dudp-address=${udp-address} - - - - create1 - - create - - - ${basedir}/target/server1 - ${basedir}/target/classes/activemq/server1 - -Dudp-address=${udp-address} - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.ReplicatedTransactionFailoverExample - - ${basedir}/target/server0 - ${basedir}/target/server1 - - - - - - - org.apache.activemq.examples.jms - artemis-jms-replicated-transaction-failover-example - ${project.version} - - - - - - - + + + + org.apache.activemq + artemis-maven-plugin + + + create0 + + create + + + ${basedir}/target/server0 + ${basedir}/target/classes/activemq/server0 + -Dudp-address=${udp-address} + + + + create1 + + create + + + ${basedir}/target/server1 + ${basedir}/target/classes/activemq/server1 + -Dudp-address=${udp-address} + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.ReplicatedTransactionFailoverExample + + + ${basedir}/target/server0 + ${basedir}/target/server1 + + + + + + + org.apache.activemq.examples.jms + replicated-transaction-failover + ${project.version} + + + + + diff --git a/examples/jms/replicated-transaction-failover/src/main/resources/activemq/server0/broker.xml b/examples/jms/replicated-transaction-failover/src/main/resources/activemq/server0/broker.xml index 9233f17aa5..f8b076a972 100644 --- a/examples/jms/replicated-transaction-failover/src/main/resources/activemq/server0/broker.xml +++ b/examples/jms/replicated-transaction-failover/src/main/resources/activemq/server0/broker.xml @@ -29,13 +29,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/replicated-transaction-failover/src/main/resources/activemq/server1/broker.xml b/examples/jms/replicated-transaction-failover/src/main/resources/activemq/server1/broker.xml index 848525ee20..f64af4e30b 100644 --- a/examples/jms/replicated-transaction-failover/src/main/resources/activemq/server1/broker.xml +++ b/examples/jms/replicated-transaction-failover/src/main/resources/activemq/server1/broker.xml @@ -29,13 +29,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/request-reply/pom.xml b/examples/jms/request-reply/pom.xml index e8849d81fd..74dd41302f 100644 --- a/examples/jms/request-reply/pom.xml +++ b/examples/jms/request-reply/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-request-reply-example + request-reply jar ActiveMQ Artemis JMS Request Reply Example @@ -37,70 +38,84 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.RequestReplyExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-request-reply-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + --queues + exampleQueue + + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.RequestReplyExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + request-reply + ${project.version} + + + + + diff --git a/examples/jms/request-reply/src/main/resources/activemq/server0/artemis-roles.properties b/examples/jms/request-reply/src/main/resources/activemq/server0/artemis-roles.properties deleted file mode 100644 index 4e2d44cec4..0000000000 --- a/examples/jms/request-reply/src/main/resources/activemq/server0/artemis-roles.properties +++ /dev/null @@ -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 \ No newline at end of file diff --git a/examples/jms/request-reply/src/main/resources/activemq/server0/artemis-users.properties b/examples/jms/request-reply/src/main/resources/activemq/server0/artemis-users.properties deleted file mode 100644 index 4e2d44cec4..0000000000 --- a/examples/jms/request-reply/src/main/resources/activemq/server0/artemis-users.properties +++ /dev/null @@ -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 \ No newline at end of file diff --git a/examples/jms/request-reply/src/main/resources/activemq/server0/broker.xml b/examples/jms/request-reply/src/main/resources/activemq/server0/broker.xml deleted file mode 100644 index 6c344c28f8..0000000000 --- a/examples/jms/request-reply/src/main/resources/activemq/server0/broker.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - - - - ${data.dir}/server0/data/messaging/bindings - - ${data.dir}/server0/data/messaging/journal - - ${data.dir}/server0/data/messaging/largemessages - - ${data.dir}/server0/data/messaging/paging - - - - tcp://localhost:61616 - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/jms/rest/dup-send/pom.xml b/examples/jms/rest/dup-send/pom.xml index 9d1a586afd..4d1b993c74 100644 --- a/examples/jms/rest/dup-send/pom.xml +++ b/examples/jms/rest/dup-send/pom.xml @@ -22,7 +22,7 @@ under the License. 4.0.0 org.apache.activemq.examples.rest - artemis-rest-examples-pom + artemis-rests-pom 1.0.1-SNAPSHOT dup-send diff --git a/examples/jms/rest/javascript-chat/pom.xml b/examples/jms/rest/javascript-chat/pom.xml index 63958cc055..9c8418886c 100644 --- a/examples/jms/rest/javascript-chat/pom.xml +++ b/examples/jms/rest/javascript-chat/pom.xml @@ -22,7 +22,7 @@ under the License. 4.0.0 org.apache.activemq.examples.rest - artemis-rest-examples-pom + artemis-rests-pom 1.0.1-SNAPSHOT javascript-chat diff --git a/examples/jms/rest/jms-to-rest/pom.xml b/examples/jms/rest/jms-to-rest/pom.xml index 08f7faea3b..0ccd4d825a 100644 --- a/examples/jms/rest/jms-to-rest/pom.xml +++ b/examples/jms/rest/jms-to-rest/pom.xml @@ -22,7 +22,7 @@ under the License. 4.0.0 org.apache.activemq.examples.rest - artemis-rest-examples-pom + artemis-rests-pom 1.0.1-SNAPSHOT mixed-jms-rest diff --git a/examples/jms/rest/pom.xml b/examples/jms/rest/pom.xml index e19e7aa076..57252e7036 100644 --- a/examples/jms/rest/pom.xml +++ b/examples/jms/rest/pom.xml @@ -28,7 +28,7 @@ under the License. org.apache.activemq.examples.rest - artemis-rest-examples-pom + artemis-rests-pom pom ActiveMQ Artemis REST Examples diff --git a/examples/jms/rest/push/pom.xml b/examples/jms/rest/push/pom.xml index 251fcaf37b..4a5ba535b9 100644 --- a/examples/jms/rest/push/pom.xml +++ b/examples/jms/rest/push/pom.xml @@ -22,7 +22,7 @@ under the License. 4.0.0 org.apache.activemq.examples.rest - artemis-rest-examples-pom + artemis-rests-pom 1.0.1-SNAPSHOT push diff --git a/examples/jms/scale-down/pom.xml b/examples/jms/scale-down/pom.xml index 596273b970..bba30e2b46 100644 --- a/examples/jms/scale-down/pom.xml +++ b/examples/jms/scale-down/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -42,67 +43,63 @@ under the License. ${project.version} - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - - - example - - - - org.apache.activemq - artemis-maven-plugin - - - create0 - - create - - - ${basedir}/target/server0 - ${basedir}/target/classes/activemq/server0 - -Dudp-address=${udp-address} - - - - create1 - - create - - - ${basedir}/target/server1 - ${basedir}/target/classes/activemq/server1 - -Dudp-address=${udp-address} - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.ScaleDownExample - - ${basedir}/target/server0 - ${basedir}/target/server1 - - - - - - - org.apache.activemq.examples.jms - scale-down - ${project.version} - - - - - - - + + + + org.apache.activemq + artemis-maven-plugin + + + create0 + + create + + + ${basedir}/target/server0 + ${basedir}/target/classes/activemq/server0 + -Dudp-address=${udp-address} + + + + create1 + + create + + + ${basedir}/target/server1 + ${basedir}/target/classes/activemq/server1 + -Dudp-address=${udp-address} + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.ScaleDownExample + + ${basedir}/target/server0 + ${basedir}/target/server1 + + + + + + + org.apache.activemq.examples.jms + scale-down + ${project.version} + + + + + diff --git a/examples/jms/scale-down/readme.html b/examples/jms/scale-down/readme.html index a73a170bf4..c129764d46 100644 --- a/examples/jms/scale-down/readme.html +++ b/examples/jms/scale-down/readme.html @@ -27,6 +27,9 @@ under the License.

            JMS Colocated Failover Shared Store Example

            +
            To run the example, simply type mvn verify from this directory.
            + +

            This example demonstrates how you can configure a live server to scale down messages to another live server on shutdown.

            This example starts 2 live servers each one with a connector configured for the other live server.

            The second live server is killed and its messages are scaled down to the first server on shutdown.

            @@ -44,128 +47,5 @@ under the License. </ha-policy> -

            Example step-by-step

            -

            To run the example, simply type mvn verify -Pexample from this directory

            - -
              -
            1. Get an initial context for looking up JNDI for both servers
            2. -
              -           
              -    initialContext1 = getContext(1);
              -    initialContext = getContext(0);
              -   
              -        
              - -
            3. Look up the JMS resources from JNDI
            4. -
              -           
              -    Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue");
              -    ConnectionFactory connectionFactory = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
              -    ConnectionFactory connectionFactory1 = (ConnectionFactory)initialContext1.lookup("/ConnectionFactory");
              -           
              -        
              - -
            5. Create a JMS Connections
            6. -
              -           
              -    connection = connectionFactory.createConnection();
              -    connection1 = connectionFactory1.createConnection();
              -           
              -        
              - -
            7. Create a *non-transacted* JMS Session with client acknowledgement
            8. -
              -           
              -    Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
              -    Session session1 = connection1.createSession(false, Session.CLIENT_ACKNOWLEDGE);
              -           
              -        
              - -
            9. Create a JMS MessageProducer
            10. -
              -           
              -    MessageProducer producer = session.createProducer(queue);
              -    MessageProducer producer1 = session1.createProducer(queue);
              -           
              -        
              - -
            11. Send some messages to both servers
            12. -
              -          
              -    for (int i = 0; i < numMessages; i++)
              -    {
              -      TextMessage message = session.createTextMessage("This is text message " + i);
              -      producer.send(message);
              -      System.out.println("Sent message: " + message.getText());
              -      message = session1.createTextMessage("This is another text message " + i);
              -      producer1.send(message);
              -      System.out.println("Sent message: " + message.getText());
              -    }
              -          
              -        
              - -
            13. Crash server #0, the live server
            14. -
              -          
              -    killServer(0);
              -          
              -        
              - -
            15. start the connection ready to receive messages
            16. -
              -           
              -    connection.start();
              -           
              -        
              - -
            17. create a consumer
            18. -
              -           
              -    MessageConsumer consumer = session.createConsumer(queue);
              -            
              -        
              - -
            19. Receive and acknowledge all of the sent messages, you will notice that messages from both servers are received
            20. -
              -           
              -    TextMessage message0 = null;
              -    for (int i = 0; i < numMessages; i++)
              -    {
              -       message0 = (TextMessage)consumer.receive(5000);
              -       System.out.println("Got message: " + message0.getText());
              -    }
              -    message0.acknowledge();
              -           
              -        
              - -
            21. And finally (no pun intended), always remember to close your JMS resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
            22. - -
              -           
              -    finally
              -    {
              -       if (connection != null)
              -       {
              -       connection.close();
              -       }
              -
              -       if (initialContext != null)
              -       {
              -       initialContext.close();
              -       }
              -       if (connection1 != null)
              -       {
              -       connection1.close();
              -       }
              -
              -       if (initialContext1 != null)
              -       {
              -       initialContext1.close();
              -       }
              -    }
              -           
              -        
              - -
            diff --git a/examples/jms/scale-down/src/main/resources/activemq/server0/broker.xml b/examples/jms/scale-down/src/main/resources/activemq/server0/broker.xml index 1a08c9dd33..559bb5aad2 100644 --- a/examples/jms/scale-down/src/main/resources/activemq/server0/broker.xml +++ b/examples/jms/scale-down/src/main/resources/activemq/server0/broker.xml @@ -29,13 +29,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/scale-down/src/main/resources/activemq/server1/broker.xml b/examples/jms/scale-down/src/main/resources/activemq/server1/broker.xml index 87dd4aab0e..6211cd3163 100644 --- a/examples/jms/scale-down/src/main/resources/activemq/server1/broker.xml +++ b/examples/jms/scale-down/src/main/resources/activemq/server1/broker.xml @@ -29,13 +29,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/scheduled-message/pom.xml b/examples/jms/scheduled-message/pom.xml index cfda2ac233..15653a9669 100644 --- a/examples/jms/scheduled-message/pom.xml +++ b/examples/jms/scheduled-message/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-scheduled-message-example + scheduled-message jar ActiveMQ Artemis JMS Scheduled Message Example @@ -42,71 +43,81 @@ under the License. ${project.version} - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.ScheduledMessageExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-scheduled-message-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.ScheduledMessageExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + scheduled-message + ${project.version} + + + + + diff --git a/examples/jms/scheduled-message/readme.html b/examples/jms/scheduled-message/readme.html index b2d1621a03..e87406da81 100644 --- a/examples/jms/scheduled-message/readme.html +++ b/examples/jms/scheduled-message/readme.html @@ -27,11 +27,14 @@ under the License.

            JMS Scheduled Message Example

            +
            To run the example, simply type mvn verify from this directory, 
            or mvn -PnoServer verify if you want to start and create the server manually.
            + +

            This example shows you how to send a scheduled message to a JMS Queue using ActiveMQ Artemis.

            -

            A Scheduled Message is a message that will be delivered at a time specified by the sender. To do this, - simply set a HDR_SCHEDULED_DELIVERY_TIME header property. The value of the property should be the time of +

            A Scheduled Message is a message that will be delivered at a time specified by the sender. To do this, + simply set a HDR_SCHEDULED_DELIVERY_TIME header property. The value of the property should be the time of delivery in milliseconds.

            - +

            In this example, a message is created with the scheduled delivery time set to 5 seconds after the current time.

            @@ -120,12 +123,12 @@ under the License.
          - +

          More information

          - + - + diff --git a/examples/jms/security/pom.xml b/examples/jms/security/pom.xml index a58e17701c..9bc4d1a2a9 100644 --- a/examples/jms/security/pom.xml +++ b/examples/jms/security/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-security-example + security jar ActiveMQ Artemis JMS Security Example @@ -37,73 +38,83 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - bill - activemq - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.SecurityExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-security-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + bill + activemq + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.SecurityExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + security + ${project.version} + + + + + diff --git a/examples/jms/security/readme.html b/examples/jms/security/readme.html index 4cca6a0ff0..e694c3aaec 100644 --- a/examples/jms/security/readme.html +++ b/examples/jms/security/readme.html @@ -27,55 +27,58 @@ under the License.

          JMS Security Example

          +
          To run the example, simply type mvn verify from this directory, 
          or mvn -PnoServer verify if you want to start and create the server manually.
          + +

          This example shows how to configure and use security using ActiveMQ Artemis.

          - -

          With security properly configured, ActiveMQ Artemis can restrict client access to its resources, including - connection creation, message sending/receiving, etc. This is done by configuring users and roles as well as permissions in + +

          With security properly configured, ActiveMQ Artemis can restrict client access to its resources, including + connection creation, message sending/receiving, etc. This is done by configuring users and roles as well as permissions in the configuration files.

          ActiveMQ Artemis supports wild-card security configuration. This feature makes security configuration very flexible and enables fine-grained control over permissions in an efficient way.

          - +

          For a full description of how to configure security with ActiveMQ Artemis, please consult the user manual.

          - +

          This example demonstrates how to configure users/roles, how to configure topics with proper permissions using wild-card expressions, and how they take effects in a simple program.

          - +

          First we need to configure users with roles. Users and Roles are configured in activemq-users.xml. This example has four users configured as below

          - +
                
           		   <user name="bill" password="activemq">
           		      <role name="user"/>
           		   </user>
          -		  
          +
           		   <user name="andrew" password="activemq1">
           		      <role name="europe-user"/>
           		      <role name="user"/>
           		   </user>
          -		   
          +
           		   <user name="frank" password="activemq2">
           		      <role name="us-user"/>
           		      <role name="news-user"/>
           		      <role name="user"/>
           		   </user>
          -		   
          +
           		   <user name="sam" password="activemq3">
           		      <role name="news-user"/>
           		      <role name="user"/>
           		   </user>
                
                
          - +

          Each user has three properties available: user name, password, and roles it belongs to. It should be noted that a user can belong to more than one role. In the above configuration, all users belong to role 'user'. User 'andrew' also belongs to role 'europe-user', user 'frank' also belongs to 'us-user' and 'news-user' and user 'sam' also belongs to 'news-user'.

          - User name and password consists of a valid account that can be used to establish connections to a ActiveMQ Artemis server, while + User name and password consists of a valid account that can be used to establish connections to a ActiveMQ Artemis server, while roles are used in controlling the access privileges against ActiveMQ Artemis topics and queues. You can achieve this control by configuring proper permissions in broker.xml, like the following

          @@ -90,7 +93,7 @@ under the License. <permission type="send" roles="user"/> <permission type="consume" roles="user"/> </security-setting> - + <security-setting match="jms.topic.news.europe.#"> <permission type="createDurableQueue" roles="user"/> <permission type="deleteDurableQueue" roles="user"/> @@ -99,7 +102,7 @@ under the License. <permission type="send" roles="europe-user"/> <permission type="consume" roles="news-user"/> </security-setting> - + <security-setting match="jms.topic.news.us.#"> <permission type="createDurableQueue" roles="user"/> <permission type="deleteDurableQueue" roles="user"/> @@ -110,22 +113,22 @@ under the License. </security-setting> </security-settings> - -

          Permissions can be defined on any group of queues, by using a wildcard. You can easily specify + +

          Permissions can be defined on any group of queues, by using a wildcard. You can easily specify wildcards to apply certain permissions to a set of matching queues and topics. In the above configuration we have created four sets of permissions, each set matches against a special group of targets, indicated by wild-card match attributes.

          - +

          You can provide a very broad permission control as a default and then add more strict control over specific addresses. By the above we define the following access rules:

          - +
        3. Only role 'us-user' can create/delete and pulish messages to topics whose names match wild-card pattern 'news.us.#'.
        4. Only role 'europe-user' can create/delete and publish messages to topics whose names match wild-card pattern 'news.europe.#'.
        5. Only role 'news-user' can subscribe messages to topics whose names match wild-card pattern 'news.us.#' and 'news.europe.#'.
        6. For any other topics that don't match any of the above wild-card patterns, permissions are granted to users of role 'user'.
        7. - -

          To illustrate the effect of permissions, three topics are deployed. Topic 'genericTopic' matches 'jms.topic.#' wild-card, topic 'news.europe.europeTopic' matches + +

          To illustrate the effect of permissions, three topics are deployed. Topic 'genericTopic' matches 'jms.topic.#' wild-card, topic 'news.europe.europeTopic' matches jms.topic.news.europe.#' wild-cards, and topic 'news.us.usTopic' matches 'jms.topic.news.us.#'.

          - +

          With ActiveMQ Artemis, the security manager is also configurable. You can use JAASSecurityManager or JBossASSecurityManager based on you need. Please check out the activemq-beans.xml for how to do. In this example we just use the basic ActiveMQSecurityManagerImpl which reads users/roles/passwords from the xml file activemq-users.xml. @@ -286,7 +289,7 @@ under the License. checkUserReceiveNoSend(usTopic, samConnection, "sam", frankConnection); - +

        8. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
        9. @@ -309,7 +312,7 @@ under the License.
                         {
                            samConnection.close();
                         }
          -		         
          +
                         // Also the initialContext
                         if (initialContext != null)
                         {
          diff --git a/examples/jms/send-acknowledgements/pom.xml b/examples/jms/send-acknowledgements/pom.xml
          index 6d22b092ce..b53c1f27c0 100644
          --- a/examples/jms/send-acknowledgements/pom.xml
          +++ b/examples/jms/send-acknowledgements/pom.xml
          @@ -18,7 +18,8 @@ specific language governing permissions and limitations
           under the License.
           -->
           
          -
          +
              4.0.0
           
              
          @@ -27,7 +28,7 @@ under the License.
                 1.0.1-SNAPSHOT
              
           
          -   artemis-jms-send-acknowledgements-example
          +   send-acknowledgements
              jar
              ActiveMQ Artemis JMS Send Acknowledgements Example
           
          @@ -41,72 +42,72 @@ under the License.
                    artemis-jms-client
                    ${project.version}
                 
          -      
          -         org.apache.geronimo.specs
          -         geronimo-jms_2.0_spec
          -      
              
           
              
                 
          -         example
          -         
          -            
          -               
          -                  org.apache.activemq
          -                  artemis-maven-plugin
          -                  
          -                     
          -                        create
          -                        
          -                           create
          -                        
          -                     
          -                     
          -                        start
          -                        
          -                           cli
          -                        
          -                        
          -                           true
          -                           tcp://localhost:61616
          -                           
          -                              run
          -                           
          -                        
          -                     
          -                     
          -                        runClient
          -                        
          -                           runClient
          -                        
          -                        
          -                           org.apache.activemq.artemis.jms.example.SendAcknowledgementsExample
          -                        
          -                     
          -                     
          -                        stop
          -                        
          -                           cli
          -                        
          -                        
          -                           
          -                              stop
          -                           
          -                        
          -                     
          -                  
          -                  
          -                     
          -                        org.apache.activemq.examples.jms
          -                        artemis-jms-send-acknowledgements-example
          -                        ${project.version}
          -                     
          -                  
          -               
          -            
          -         
          +         
          +         noServer
          +         
          +            true
          +         
                 
              
          +   
          +      
          +         
          +            org.apache.activemq
          +            artemis-maven-plugin
          +            
          +               
          +                  create
          +                  
          +                     create
          +                  
          +               
          +               
          +                  start
          +                  
          +                     cli
          +                  
          +                  
          +                     true
          +                     tcp://localhost:61616
          +                     
          +                        run
          +                     
          +                  
          +               
          +               
          +                  runClient
          +                  
          +                     runClient
          +                  
          +                  
          +                     org.apache.activemq.artemis.jms.example.SendAcknowledgementsExample
          +                  
          +               
          +               
          +                  stop
          +                  
          +                     cli
          +                  
          +                  
          +                     
          +                        stop
          +                     
          +                  
          +               
          +            
          +            
          +               
          +                  org.apache.activemq.examples.jms
          +                  send-acknowledgements
          +                  ${project.version}
          +               
          +            
          +         
          +      
          +   
           
           
          diff --git a/examples/jms/send-acknowledgements/readme.html b/examples/jms/send-acknowledgements/readme.html
          index 1077f32fd6..6e7e8bed12 100644
          --- a/examples/jms/send-acknowledgements/readme.html
          +++ b/examples/jms/send-acknowledgements/readme.html
          @@ -27,9 +27,12 @@ under the License.
             
                

          Asynchronous Send Acknowledgements Example

          +
          To run the example, simply type mvn verify from this directory, 
          or mvn -PnoServer verify if you want to start and create the server manually.
          + +

          Asynchronous Send Acknowledgements are an advanced feature of ActiveMQ Artemis which allow you to receive acknowledgements that messages were successfully received at the server in a separate thread to the sending thread

          -

          In this example we create a normal JMS session, then set a SendAcknowledgementHandler on the JMS +

          In this example we create a normal JMS session, then set a SendAcknowledgementHandler on the JMS session's underlying core session. We send many messages to the server without blocking and asynchronously receive send acknowledgements via the SendAcknowledgementHandler. @@ -64,12 +67,12 @@ under the License. class MySendAcknowledgementsHandler implements SendAcknowledgementHandler { int count = 0; - + public void sendAcknowledged(final Message message) { System.out.println("Received send acknowledgement for message " + count++); - } - } + } + }

          @@ -82,9 +85,9 @@ under the License.
                      
                    ClientSession coreSession = ((ActiveMQSession)session).getCoreSession();
          -         
          +
                    coreSession.setSendAcknowledgementHandler(new MySendAcknowledgementsHandler());
          -           
          +
                      
                   
          @@ -92,8 +95,8 @@ under the License.
                      
                    MessageProducer producer = session.createProducer(queue);
          -         
          -         producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);           
          +
          +         producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
                      
                   
          @@ -101,19 +104,19 @@ under the License.
                      
                    final int numMessages = 5000;
          -         
          +
                    for (int i = 0; i < numMessages; i++)
                    {
                       javax.jms.Message jmsMessage = session.createMessage();
          -            
          +
                       producer.send(jmsMessage);
          -            
          +
                       System.out.println("Sent message " + i);
          -         }           
          +         }
                      
                   
          - +
        10. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
        11. diff --git a/examples/jms/spring-integration/pom.xml b/examples/jms/spring-integration/pom.xml
          index fcc6d9f6f3..5c30fd64c6 100644
          --- a/examples/jms/spring-integration/pom.xml
          +++ b/examples/jms/spring-integration/pom.xml
          @@ -18,7 +18,8 @@ specific language governing permissions and limitations
           under the License.
           -->
           
          -
          +
              4.0.0
           
              
          @@ -27,7 +28,7 @@ under the License.
                 1.0.1-SNAPSHOT
              
           
          -   artemis-jms-spring-integration-example
          +   spring-integration
              jar
              ActiveMQ Artemis JMS Spring Integration Example
           
          @@ -51,36 +52,31 @@ under the License.
                 
              
           
          -   
          -      
          -         example
          -         
          -            
          -               
          -                  org.apache.activemq
          -                  artemis-maven-plugin
          -                  
          -                     
          -                        runClient
          -                        
          -                           runClient
          -                        
          -                        
          -                           org.apache.activemq.artemis.jms.example.SpringExample
          -                        
          -                     
          -                  
          -                  
          -                     
          -                        org.apache.activemq.examples.jms
          -                        artemis-jms-spring-integration-example
          -                        ${project.version}
          -                     
          -                  
          -               
          -            
          -         
          -      
          -   
          +   
          +      
          +         
          +            org.apache.activemq
          +            artemis-maven-plugin
          +            
          +               
          +                  runClient
          +                  
          +                     runClient
          +                  
          +                  
          +                     org.apache.activemq.artemis.jms.example.SpringExample
          +                  
          +               
          +            
          +            
          +               
          +                  org.apache.activemq.examples.jms
          +                  spring-integration
          +                  ${project.version}
          +               
          +            
          +         
          +      
          +   
           
           
          diff --git a/examples/jms/spring-integration/readme.html b/examples/jms/spring-integration/readme.html
          index 08615287b8..ddb15a7d81 100644
          --- a/examples/jms/spring-integration/readme.html
          +++ b/examples/jms/spring-integration/readme.html
          @@ -26,10 +26,10 @@ under the License.
              
              
                 

          ActiveMQ Artemis Spring Example

          - +

          This examples shows how to setup and run an embedded JMS server within a Spring ApplicationContext using ActiveMQ Artemis along with ActiveMQ Artemis configuration files.

          - -

          Example step-by-step

          + +

          Example step-by-step

          YOU MUST DOWNLOAD THE SPRING LIBRARIES TO RUN THIS EXAMPLE!!! You must also modify the build.xml file to include the spring jars. You'll see the placeholder that is already there.

          To run the example, simply type mvn verify -Pexample from this directory

          diff --git a/examples/jms/ssl-enabled/pom.xml b/examples/jms/ssl-enabled/pom.xml index 7c6e4f82b2..c0a21a1d1e 100644 --- a/examples/jms/ssl-enabled/pom.xml +++ b/examples/jms/ssl-enabled/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-ssl-enabled-example + ssl-enabled jar ActiveMQ Artemis JMS SSL Enabled Example @@ -37,71 +38,81 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:5500?sslEnabled=true&trustStorePath=activemq/server0/activemq.example.truststore&trustStorePassword=activemqexample - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.SSLExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-ssl-enabled-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + + + start + + cli + + + ${noServer} + true + tcp://localhost:5500?sslEnabled=true&trustStorePath=activemq/server0/activemq.example.truststore&trustStorePassword=activemqexample + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.SSLExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + ssl-enabled + ${project.version} + + + + + diff --git a/examples/jms/ssl-enabled/readme.html b/examples/jms/ssl-enabled/readme.html index 42db4ded7b..f1d94b5951 100644 --- a/examples/jms/ssl-enabled/readme.html +++ b/examples/jms/ssl-enabled/readme.html @@ -27,11 +27,14 @@ under the License.

          JMS SSL Example

          +
          To run the example, simply type mvn verify from this directory, 
          or mvn -PnoServer verify if you want to start and create the server manually.
          + +

          This example shows you how to configure SSL with ActiveMQ Artemis to send and receive message.

          - +

          Using SSL can make your messaging applications interact with ActiveMQ Artemis securely. An application can be secured transparently without extra coding effort. To secure your messaging application with SSL, you need to configure connector and acceptor as follows:

          - +

                      
          @@ -46,98 +49,8 @@ under the License.
                      
                   

          - +

          In the configuration, the activemq.example.keystore is the key store file holding the server's certificate. The activemq.example.truststore is the file holding the certificates which the client trusts (i.e. the server's certificate exported from activemq.example.keystore). They are pre-generated for illustration purpose1.

          - - -

          Example step-by-step

          -

          To run the example, simply type mvn verify -Pexample from this directory

          - -
            -
          1. First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the client-jndi.properties file in the directory ../common/config
          2. -
            -           InitialContext initialContext = getContext();
            -        
            - -
          3. We look-up the JMS queue object from JNDI
          4. -
            -           Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");
            -        
            - -
          5. We look-up the JMS connection factory object from JNDI
          6. -
            -           ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
            -        
            - -
          7. We create a JMS connection
          8. -
            -           connection = cf.createConnection();
            -        
            - -
          9. We create a JMS session. The session is created as non transacted and will auto acknowledge messages.
          10. -
            -           Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            -        
            - -
          11. We create a JMS message producer on the session. This will be used to send the messages.
          12. -
            -          MessageProducer messageProducer = session.createProducer(topic);
            -       
            - -
          13. We create a JMS text message that we are going to send.
          14. -
            -           TextMessage message = session.createTextMessage("This is a text message");
            -        
            - -
          15. We send message to the queue
          16. -
            -           messageProducer.send(message);
            -        
            - -
          17. We create a JMS Message Consumer to receive the message.
          18. -
            -           MessageConsumer messageConsumer = session.createConsumer(queue);
            -        
            - -
          19. We start the connection. In order for delivery to occur on any consumers or subscribers on a connection, the connection must be started
          20. -
            -           connection.start();
            -        
            - -
          21. The message arrives at the consumer. In this case we use a timeout of 5000 milliseconds but we could use a blocking 'receive()'
          22. -
            -           TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
            -        
            - -
          23. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
          24. - -
            -           finally
            -           {
            -              if (initialContext != null)
            -              {
            -                initialContext.close();
            -              }
            -              if (connection != null)
            -              {
            -                 connection.close();
            -              }
            -           }
            -        
            -
          - -
          - -
            -
          1. The stores were generating using the following commands : -
              -
            • create the keystore: keytool -genkey -keystore activemq.example.keystore -storepass activemqexample
            • -
            • export the certificate: keytool -export -keystore activemq.example.keystore -file activemq.cer
            • -
            • create the truststore: keytool -import -file activemq.cer -keystore activemq.example.truststore -storepass activemqexample
            • -
            -
          2. -
          - diff --git a/examples/jms/static-selector-jms/pom.xml b/examples/jms/static-selector-jms/pom.xml deleted file mode 100644 index 02b8fb7038..0000000000 --- a/examples/jms/static-selector-jms/pom.xml +++ /dev/null @@ -1,106 +0,0 @@ - - - - - 4.0.0 - - - org.apache.activemq.examples.jms - jms-examples - 1.0.1-SNAPSHOT - - - artemis-jms-static-selector-jms-example - jar - ActiveMQ Artemis JMS Static Selector Example - - - ${project.basedir}/../../.. - - - - - org.apache.geronimo.specs - geronimo-jms_2.0_spec - - - - - - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.StaticSelectorJMSExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-static-selector-jms-example - ${project.version} - - - - - - - - diff --git a/examples/jms/static-selector-jms/readme.html b/examples/jms/static-selector-jms/readme.html deleted file mode 100644 index 7cda4070a9..0000000000 --- a/examples/jms/static-selector-jms/readme.html +++ /dev/null @@ -1,158 +0,0 @@ - - - - - ActiveMQ Artemis Static Message Selector JMS Example - - - - - -

          Static Message Selector Example

          - -

          This example shows you how to configure a JMS queue with static message selectors (filters).

          - -

          Static message selectors are ActiveMQ's extension to message selectors as defined in JMS spec 1.1. - Rather than specifying the selector in the application code, static message selectors are defined in one of - ActiveMQ's configuration files, activemq-jms.xml, as an element called 'selector' inside each JMS queue - definition:

          - -
          
          -      	<queue name="selectorQueue">
          -            <entry name="/queue/selectorQueue">
          -      	    <selector string="color='red'"/>
          -      	</queue>
          -     
          - -

          Once configured the queue selectorQueue only delivers messages that are - that match the selector; i.e. only the messages whose color property is equal to 'red' can be received by its consumers. - Those that don't match the selector will be dropped by the queue and therefore will never be delivered to any of its consumers.

          - -

          In the example code, five messages with different color property values are sent to queue selectorQueue. - One consumer is created to receive messages from the queue. Of the five sent messages, two have a color property - set to 'red', one has it set to 'blue', another to 'green', - and one has not the color property at all. The result is that the consumer only gets the two messages - with the 'red' color.

          - - -

          Example step-by-step

          -

          To run the example, simply type mvn verify -Pexample from this directory

          - -
            -
          1. First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the client-jndi.properties file in the directory ../common/config
          2. -
            -           InitialContext initialContext = getContext();
            -        
            - -
          3. We look-up the JMS queue object from JNDI, this is the queue that has the selector configured with it.
          4. -
            -           Queue queue = (Queue) initialContext.lookup("/queue/selectorQueue");
            -        
            - -
          5. We look-up the JMS connection factory object from JNDI
          6. -
            -           ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
            -        
            - -
          7. We create a JMS connection
          8. -
            -           connection = cf.createConnection();
            -        
            - -
          9. We start the connection
          10. -
            -           connection.start();
            -        
            - -
          11. We create a JMS session. The session is created as non transacted and will auto acknowledge messages.
          12. -
            -           Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            -        
            - -
          13. We create a JMS message producer on the session. This will be used to send the messages.
          14. -
            -          MessageProducer producer = session.createProducer(queue);
            -       
            - -
          15. We create a JMS message consumer that receives 'red' messages. The message listener will - check the 'color' property on each received message.
          16. -
            -           
            -         MessageConsumer redConsumer = session.createConsumer(queue);
            -         redConsumer.setMessageListener(new SimpleMessageListener("red"));
            -           
            -         
            - -
          17. We create five messages with different 'color' properties.
          18. -
            -          
            -         TextMessage redMessage1 = session.createTextMessage("Red-1");
            -         redMessage1.setStringProperty("color", "red");
            -         TextMessage redMessage2 = session.createTextMessage("Red-2");
            -         redMessage2.setStringProperty("color", "red");
            -         TextMessage greenMessage = session.createTextMessage("Green");
            -         greenMessage.setStringProperty("color", "green");
            -         TextMessage blueMessage = session.createTextMessage("Blue");
            -         blueMessage.setStringProperty("color", "blue");
            -         TextMessage normalMessage = session.createTextMessage("No color");
            -         
            -        
            - -
          19. We send those messages.
          20. -
            -          
            -         producer.send(redMessage1);
            -         System.out.println("Message sent: " + redMessage1.getText());
            -         producer.send(greenMessage);
            -         System.out.println("Message sent: " + greenMessage.getText());
            -         producer.send(blueMessage);
            -         System.out.println("Message sent: " + blueMessage.getText());
            -         producer.send(redMessage2);
            -         System.out.println("Message sent: " + redMessage2.getText());
            -         producer.send(normalMessage);
            -         System.out.println("Message sent: " + normalMessage.getText());
            -          
            -        
            - -
          21. Waiting for the message listener to check the received messages.
          22. -
            -          
            -          Thread.sleep(5000);
            -         
            -        
            - -
          23. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
          24. - -
            -           finally
            -           {
            -              if (initialContext != null)
            -              {
            -                initialContext.close();
            -              }
            -              if (connection != null)
            -              {
            -                 connection.close();
            -              }
            -           }
            -        
            -
          - - diff --git a/examples/jms/static-selector-jms/src/main/java/org/apache/activemq/artemis/jms/example/StaticSelectorJMSExample.java b/examples/jms/static-selector-jms/src/main/java/org/apache/activemq/artemis/jms/example/StaticSelectorJMSExample.java deleted file mode 100644 index 0f064175df..0000000000 --- a/examples/jms/static-selector-jms/src/main/java/org/apache/activemq/artemis/jms/example/StaticSelectorJMSExample.java +++ /dev/null @@ -1,147 +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. - */ -package org.apache.activemq.artemis.jms.example; - -import javax.jms.Connection; -import javax.jms.ConnectionFactory; -import javax.jms.JMSException; -import javax.jms.Message; -import javax.jms.MessageConsumer; -import javax.jms.MessageListener; -import javax.jms.MessageProducer; -import javax.jms.Queue; -import javax.jms.Session; -import javax.jms.TextMessage; -import javax.naming.InitialContext; -import java.util.concurrent.atomic.AtomicBoolean; - -/** - * A simple JMS example that shows how static message selectors work when using JMS config. - */ -public class StaticSelectorJMSExample -{ - public static void main(final String[] args) throws Exception - { - AtomicBoolean result = new AtomicBoolean(true); - Connection connection = null; - InitialContext initialContext = null; - try - { - // Step 1. Create an initial context to perform the JNDI lookup. - initialContext = new InitialContext(); - - // Step 2. look-up the JMS queue object from JNDI, this is the queue that has filter configured with it. - Queue queue = (Queue)initialContext.lookup("queue/exampleQueue"); - - // Step 3. look-up the JMS connection factory object from JNDI - ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("ConnectionFactory"); - - // Step 4. Create a JMS Connection - connection = cf.createConnection(); - - // Step 5. Start the connection - connection.start(); - - // Step 6. Create a JMS Session - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - Session producerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - - // Step 7. Create a JMS Message Producer - MessageProducer producer = producerSession.createProducer(queue); - - // Step 8. Create a JMS Message Consumer that receives 'red' messages - MessageConsumer redConsumer = session.createConsumer(queue); - redConsumer.setMessageListener(new SimpleMessageListener("red", result)); - - // Step 9. Create five messages with different 'color' properties - TextMessage redMessage1 = session.createTextMessage("Red-1"); - redMessage1.setStringProperty("color", "red"); - TextMessage redMessage2 = session.createTextMessage("Red-2"); - redMessage2.setStringProperty("color", "red"); - TextMessage greenMessage = session.createTextMessage("Green"); - greenMessage.setStringProperty("color", "green"); - TextMessage blueMessage = session.createTextMessage("Blue"); - blueMessage.setStringProperty("color", "blue"); - TextMessage normalMessage = session.createTextMessage("No color"); - - // Step 10. Send the Messages - producer.send(redMessage1); - System.out.println("Message sent: " + redMessage1.getText()); - producer.send(greenMessage); - System.out.println("Message sent: " + greenMessage.getText()); - producer.send(blueMessage); - System.out.println("Message sent: " + blueMessage.getText()); - producer.send(redMessage2); - System.out.println("Message sent: " + redMessage2.getText()); - producer.send(normalMessage); - System.out.println("Message sent: " + normalMessage.getText()); - - // Step 11. Waiting for the message listener to check the received messages. - Thread.sleep(5000); - - if (!result.get()) - throw new IllegalStateException(); - } - finally - { - // Step 12. Be sure to close our JMS resources! - if (initialContext != null) - { - initialContext.close(); - } - if (connection != null) - { - connection.close(); - } - } - } -} - -class SimpleMessageListener implements MessageListener -{ - private final String name; - private AtomicBoolean result; - - public SimpleMessageListener(final String listener, AtomicBoolean result) - { - name = listener; - this.result = result; - } - - public void onMessage(final Message msg) - { - TextMessage textMessage = (TextMessage)msg; - try - { - String colorProp = msg.getStringProperty("color"); - System.out.println("Receiver " + name + - " receives message [" + - textMessage.getText() + - "] with color property: " + - colorProp); - if (colorProp != null && !colorProp.equals(name)) - { - result.set(false); - } - } - catch (JMSException e) - { - e.printStackTrace(); - result.set(false); - } - } -} \ No newline at end of file diff --git a/examples/jms/static-selector-jms/src/main/resources/activemq/server0/artemis-roles.properties b/examples/jms/static-selector-jms/src/main/resources/activemq/server0/artemis-roles.properties deleted file mode 100644 index 4e2d44cec4..0000000000 --- a/examples/jms/static-selector-jms/src/main/resources/activemq/server0/artemis-roles.properties +++ /dev/null @@ -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 \ No newline at end of file diff --git a/examples/jms/static-selector-jms/src/main/resources/activemq/server0/artemis-users.properties b/examples/jms/static-selector-jms/src/main/resources/activemq/server0/artemis-users.properties deleted file mode 100644 index 4e2d44cec4..0000000000 --- a/examples/jms/static-selector-jms/src/main/resources/activemq/server0/artemis-users.properties +++ /dev/null @@ -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 \ No newline at end of file diff --git a/examples/jms/static-selector-jms/src/main/resources/activemq/server0/broker.xml b/examples/jms/static-selector-jms/src/main/resources/activemq/server0/broker.xml deleted file mode 100644 index cdeb5343e0..0000000000 --- a/examples/jms/static-selector-jms/src/main/resources/activemq/server0/broker.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - - - - - - - - ${data.dir:../data}/bindings - - ${data.dir:../data}/journal - - ${data.dir:../data}/largemessages - - ${data.dir:../data}/paging - - - - tcp://localhost:61616 - - - - - - - - - - - - - - - - - - diff --git a/examples/jms/static-selector-jms/src/main/resources/jndi.properties b/examples/jms/static-selector-jms/src/main/resources/jndi.properties deleted file mode 100644 index 93537c415a..0000000000 --- a/examples/jms/static-selector-jms/src/main/resources/jndi.properties +++ /dev/null @@ -1,20 +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. - -java.naming.factory.initial=org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory -connectionFactory.ConnectionFactory=tcp://localhost:61616 -queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/static-selector/pom.xml b/examples/jms/static-selector/pom.xml index 54881c9e8d..0880cba371 100644 --- a/examples/jms/static-selector/pom.xml +++ b/examples/jms/static-selector/pom.xml @@ -27,7 +27,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-static-selector-example + static-selector jar ActiveMQ Artemis Static Selector Example @@ -37,15 +37,22 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - + + noServer + + true + + + + org.apache.activemq @@ -56,6 +63,9 @@ under the License. create + + ${noServer} + start @@ -63,6 +73,7 @@ under the License. cli + ${noServer} true tcp://localhost:61616 @@ -85,6 +96,7 @@ under the License. cli + ${noServer} stop @@ -94,14 +106,12 @@ under the License. org.apache.activemq.examples.jms - artemis-static-selector-example + static-selector ${project.version} - -
          diff --git a/examples/jms/static-selector/readme.html b/examples/jms/static-selector/readme.html index e0a3fc314e..171f15a291 100644 --- a/examples/jms/static-selector/readme.html +++ b/examples/jms/static-selector/readme.html @@ -27,134 +27,34 @@ under the License.

          Static Message Selector Example

          +
          To run the example, simply type mvn verify from this directory, 
          or mvn -PnoServer verify if you want to start and create the server manually.
          + +

          This example shows you how to configure a ActiveMQ Artemis queue with static message selectors (filters) (to configure a static selector directly on a JMS queue, please see the static-selector-jms example).

          - +

          Static message selectors are ActiveMQ's extension to message selectors as defined in JMS spec 1.1. - Rather than specifying the selector in the application code, static message selectors are defined in one of + Rather than specifying the selector in the application code, static message selectors are defined in one of ActiveMQ's configuration files, broker.xml, as an element called 'filter' inside each queue definition, like

          - +
          
          -      <queues>     
          +      <queues>
                 	<queue name="jms.queue.selectorQueue">
                 	    <address>jms.queue.selectorQueue</address>
                 	    <filter string="color='red'"/>
                 	</queue>
                 </queues>
                
          - +

          Once configured the queue 'selectorQueue' only delivers messages that are selected against the filter, i.e., only the messages whose 'color' properties are of 'red' values can be received by its consumers. Those that don't match the filter will be dropped by the queue and therefore will never be delivered to any of its consumers.

          - +

          In the example code, five messages with different 'color' property values are sent to queue 'selectorQueue'. One consumer - is created to receive messages from the queue. Of the five sent messages, two are of 'red' color properties, one is 'blue', + is created to receive messages from the queue. Of the five sent messages, two are of 'red' color properties, one is 'blue', one is 'green' and one has not the 'color' property at all. The result is that the consumer only gets the two 'red' messages.

          - -

          Example step-by-step

          -

          To run the example, simply type mvn verify -Pexample from this directory

          - -
            -
          1. First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the client-jndi.properties file in the directory ../common/config
          2. -
            -           InitialContext initialContext = getContext();
            -        
            - -
          3. We look-up the JMS queue object from JNDI, this is the queue that has filter configured with it.
          4. -
            -           Queue queue = (Queue) initialContext.lookup("/queue/selectorQueue");
            -        
            - -
          5. We look-up the JMS connection factory object from JNDI
          6. -
            -           ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
            -        
            - -
          7. We create a JMS connection
          8. -
            -           connection = cf.createConnection();
            -        
            - -
          9. We start the connection
          10. -
            -           connection.start();
            -        
            - -
          11. We create a JMS session. The session is created as non transacted and will auto acknowledge messages.
          12. -
            -           Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            -        
            - -
          13. We create a JMS message producer on the session. This will be used to send the messages.
          14. -
            -          MessageProducer producer = session.createProducer(queue);
            -       
            - -
          15. We create a JMS message consumer that receives 'red' messages. The message listener will - check the 'color' property on each received message.
          16. -
            -           
            -         MessageConsumer redConsumer = session.createConsumer(queue);
            -         redConsumer.setMessageListener(new SimpleMessageListener("red"));
            -           
            -         
            - -
          17. We reate five messages with different 'color' properties.
          18. -
            -          
            -         TextMessage redMessage1 = session.createTextMessage("Red-1");
            -         redMessage1.setStringProperty("color", "red");
            -         TextMessage redMessage2 = session.createTextMessage("Red-2");
            -         redMessage2.setStringProperty("color", "red");
            -         TextMessage greenMessage = session.createTextMessage("Green");
            -         greenMessage.setStringProperty("color", "green");
            -         TextMessage blueMessage = session.createTextMessage("Blue");
            -         blueMessage.setStringProperty("color", "blue");
            -         TextMessage normalMessage = session.createTextMessage("No color");
            -         
            -        
            - -
          19. We send those messages.
          20. -
            -          
            -         producer.send(redMessage1);
            -         System.out.println("Message sent: " + redMessage1.getText());
            -         producer.send(greenMessage);
            -         System.out.println("Message sent: " + greenMessage.getText());
            -         producer.send(blueMessage);
            -         System.out.println("Message sent: " + blueMessage.getText());
            -         producer.send(redMessage2);
            -         System.out.println("Message sent: " + redMessage2.getText());
            -         producer.send(normalMessage);
            -         System.out.println("Message sent: " + normalMessage.getText());
            -          
            -        
            - -
          21. Waiting for the message listener to check the received messages.
          22. -
            -          
            -          Thread.sleep(5000);
            -         
            -        
            - -
          23. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
          24. - -
            -           finally
            -           {
            -              if (initialContext != null)
            -              {
            -                initialContext.close();
            -              }
            -              if (connection != null)
            -              {
            -                 connection.close();
            -              }
            -           }
            -        
            -
          diff --git a/examples/jms/stomp-websockets/pom.xml b/examples/jms/stomp-websockets/pom.xml index 64c3ced878..06fc7476a9 100644 --- a/examples/jms/stomp-websockets/pom.xml +++ b/examples/jms/stomp-websockets/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-stomp-websockets-example + stomp-websockets jar ActiveMQ Artemis JMS StompWebSocketExample Example @@ -37,71 +38,81 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.StompWebSocketExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-stomp-websockets-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.StompWebSocketExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + stomp-websockets + ${project.version} + + + + + diff --git a/examples/jms/stomp-websockets/readme.html b/examples/jms/stomp-websockets/readme.html index 6bdef7f3ef..56b2673be3 100644 --- a/examples/jms/stomp-websockets/readme.html +++ b/examples/jms/stomp-websockets/readme.html @@ -27,13 +27,16 @@ under the License.

          Stomp WebSockets Example

          +
          To run the example, simply type mvn verify from this directory, 
          or mvn -PnoServer verify if you want to start and create the server manually.
          + +

          This example shows you how to configure ActiveMQ Artemis to send and receive Stomp messages from modern web browser using Web Sockets.

          The example will start a ActiveMQ Artemis server configured with Stomp over Web Sockets and JMS. Web browsers clients and Java application will exchange message using a JMS Topic.

           <acceptor name="stomp-websocket">tcp://localhost:61614</acceptor>
          - +

          Example step-by-step

          To run the example, simply type mvn verify -Pexample from this directory

          @@ -44,7 +47,7 @@ under the License.

          You can open as many Web clients as you want and they will all exchange messages through the topic

          If you run again the Java application (with ./build.sh), the web clients will also receive its message

          - +

          Documentation

          A JavaScript library is used on the browser side to be able to use Stomp Over Web Sockets (please see its documentation for a complete description).

          diff --git a/examples/jms/stomp-websockets/src/main/resources/activemq/server0/broker.xml b/examples/jms/stomp-websockets/src/main/resources/activemq/server0/broker.xml index efceecf8e5..6a68013f07 100644 --- a/examples/jms/stomp-websockets/src/main/resources/activemq/server0/broker.xml +++ b/examples/jms/stomp-websockets/src/main/resources/activemq/server0/broker.xml @@ -29,13 +29,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/stomp/pom.xml b/examples/jms/stomp/pom.xml index 867827d5cf..eca6bee6e9 100644 --- a/examples/jms/stomp/pom.xml +++ b/examples/jms/stomp/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-stomp-example + stomp jar ActiveMQ Artemis JMS Stomp Example @@ -37,71 +38,81 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.StompExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-stomp-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.StompExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + stomp + ${project.version} + + + + + diff --git a/examples/jms/stomp/readme.html b/examples/jms/stomp/readme.html index 3935090250..8f07f11dec 100644 --- a/examples/jms/stomp/readme.html +++ b/examples/jms/stomp/readme.html @@ -27,104 +27,12 @@ under the License.

          Stomp Example

          +
          To run the example, simply type mvn verify from this directory, 
          or mvn -PnoServer verify if you want to start and create the server manually.
          + +

          This example shows you how to configure ActiveMQ Artemis to send and receive Stomp messages.

          The example will start a ActiveMQ Artemis server configured with Stomp and JMS.

          -

          The client will open a socket to send one Stomp message (using TCP directly). +

          The client will open a socket to send one Stomp message (using TCP directly). The client will then consume a message from a JMS Queue and check it is the message sent with Stomp.

          - -

          Example step-by-step

          -

          To run the example, simply type mvn verify -Pexample from this directory

          - -
            -
          1. We create a TCP socket to connect to the Stomp port -
            -          Socket socket = new Socket("localhost", 61613); 
            -        
            - -
          2. We send a CONNECT frame to connect to the server
          3. -
            -          String connectFrame = "CONNECT\n" +
            -             "login: guest\n" + 
            -             "passcode: guest\n" + 
            -             "request-id: 1\n" + 
            -             "\n" +
            -             Stomp.NULL;
            -          sendFrame(socket, connectFrame);
            -        
            - -
          4. We send a SEND frame (a Stomp message) to the destination jms.queue.exampleQueue - (which corresponds to the ActiveMQ Artemis address for the JMS Queue exampleQueue) with a text body
          5. -
            -          String text = "Hello, world from Stomp!";
            -          String message = "SEND\n" + 
            -             "destination: jms.queue.exampleQueue\n" +
            -             "\n" +
            -             text +
            -             Stomp.NULL;
            -          sendFrame(socket, message);
            -          System.out.println("Sent Stomp message: " + text);
            -        
            - -
          6. We send a DISCONNECT frame to disconnect from the server
          7. -
            -          String disconnectFrame = "DISCONNECT\n" +
            -             "\n" +
            -             Stomp.NULL;
            -          sendFrame(socket, disconnectFrame);
            -        
            - -
          8. We close the TCP socket
          9. -
            -          socket.close();
            -        
            - -
          10. We create an initial context to perform the JNDI lookup.
          11. -
            -          initialContext = getContext(0);
            -       
            - -
          12. We perform a lookup on the queue and the connection factory
          13. -
            -          Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue");
            -          ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
            -        
            - -
          14. We create a JMS Connection, Session and a MessageConsumer on the queue
          15. -
            -          connection = cf.createConnection();
            -          Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            -          MessageConsumer consumer = session.createConsumer(queue);
            -        
            - -
          16. We start the connection
          17. -
            -           connection.start();
            -        
            - -
          18. We receive the message. Stomp messages are mapped to JMS TextMessage.
          19. -
            -          TextMessage messageReceived = (TextMessage)consumer.receive(5000);
            -          System.out.println("Received JMS message: " + messageReceived.getText());
            -        
            - -
          20. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
          21. - -
            -           finally
            -           {
            -              if (initialContext != null)
            -              {
            -                initialContext.close();
            -              }
            -              if (connection != null)
            -              {
            -                 connection.close();
            -              }
            -           }
            -        
            - - - -
          diff --git a/examples/jms/stomp1.1/pom.xml b/examples/jms/stomp1.1/pom.xml index b17e9c09f0..68ed6cd873 100644 --- a/examples/jms/stomp1.1/pom.xml +++ b/examples/jms/stomp1.1/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,9 +28,9 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-stomp1.1-example + stomp1.1 jar - ActiveMQ Artemis JMS Stomp 1.1 Example + ActiveMQ Artemis JMS Stomp Example ${project.basedir}/../../.. @@ -37,71 +38,81 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.StompExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-stomp1.1-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.StompExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + stomp1.1 + ${project.version} + + + + + diff --git a/examples/jms/stomp1.1/readme.html b/examples/jms/stomp1.1/readme.html index afa0d06764..5c3fe611b0 100644 --- a/examples/jms/stomp1.1/readme.html +++ b/examples/jms/stomp1.1/readme.html @@ -27,112 +27,12 @@ under the License.

          Stomp 1.1 Example

          +
          To run the example, simply type mvn verify from this directory, 
          or mvn -PnoServer verify if you want to start and create the server manually.
          + +

          This example shows you how to configure ActiveMQ Artemis to send and receive Stomp messages using Stomp 1.1 protocol.

          The example will start a ActiveMQ Artemis server configured with Stomp and JMS.

          -

          The client will open a socket to initiate a Stomp 1.1 connection and then send one Stomp message (using TCP directly). +

          The client will open a socket to initiate a Stomp 1.1 connection and then send one Stomp message (using TCP directly). The client will then consume a message from a JMS Queue and check it is the message sent with Stomp.

          - -

          Example step-by-step

          -

          To run the example, simply type mvn verify -Pexample from this directory

          - -
            -
          1. We create a TCP socket to connect to the Stomp port -
            -          Socket socket = new Socket("localhost", 61613); 
            -        
            - -
          2. We negotiate a Stomp 1.1 connection to the server
          3. -
            -         String connectFrame = "CONNECT\n" + 
            -            "accept-version:1.1\n" +
            -            "host:localhost\n" +
            -            "login:guest\n" +
            -            "passcode:guest\n" +
            -            "request-id:1\n" +
            -            "\n" +
            -            END_OF_FRAME;
            -          sendFrame(socket, connectFrame);
            -        
            - -
          4. We receive a response showing that the connection version
          5. -
            -         String response = receiveFrame(socket);
            -         System.out.println("response: " + response);
            -        
            - -
          6. We send a SEND frame (a Stomp message) to the destination jms.queue.exampleQueue - (which corresponds to the ActiveMQ Artemis address for the JMS Queue exampleQueue) with a text body
          7. -
            -          String text = "Hello World from Stomp 1.1 !";
            -          String message = "SEND\n" + 
            -             "destination:jms.queue.exampleQueue\n" +
            -             "\n" +
            -             text +
            -             END_OF_FRAME;
            -          sendFrame(socket, message);
            -          System.out.println("Sent Stomp message: " + text);
            -        
            - -
          8. We send a DISCONNECT frame to disconnect from the server
          9. -
            -          String disconnectFrame = "DISCONNECT\n" +
            -             "\n" +
            -             Stomp.NULL;
            -          sendFrame(socket, disconnectFrame);
            -        
            - -
          10. We close the TCP socket
          11. -
            -          socket.close();
            -        
            - -
          12. We create an initial context to perform the JNDI lookup.
          13. -
            -          initialContext = getContext(0);
            -       
            - -
          14. We perform a lookup on the queue and the connection factory
          15. -
            -          Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue");
            -          ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
            -        
            - -
          16. We create a JMS Connection, Session and a MessageConsumer on the queue
          17. -
            -          connection = cf.createConnection();
            -          Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            -          MessageConsumer consumer = session.createConsumer(queue);
            -        
            - -
          18. We start the connection
          19. -
            -           connection.start();
            -        
            - -
          20. We receive the message. Stomp messages are mapped to JMS TextMessage.
          21. -
            -          TextMessage messageReceived = (TextMessage)consumer.receive(5000);
            -          System.out.println("Received JMS message: " + messageReceived.getText());
            -        
            - -
          22. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
          23. - -
            -           finally
            -           {
            -              if (initialContext != null)
            -              {
            -                initialContext.close();
            -              }
            -              if (connection != null)
            -              {
            -                 connection.close();
            -              }
            -           }
            -        
            - - - -
          diff --git a/examples/jms/stomp1.1/src/main/resources/activemq/server0/broker.xml b/examples/jms/stomp1.1/src/main/resources/activemq/server0/broker.xml index 9688ae9824..fea1cca2b6 100644 --- a/examples/jms/stomp1.1/src/main/resources/activemq/server0/broker.xml +++ b/examples/jms/stomp1.1/src/main/resources/activemq/server0/broker.xml @@ -29,13 +29,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/stomp1.2/pom.xml b/examples/jms/stomp1.2/pom.xml index e673181ea9..3cee1dbad8 100644 --- a/examples/jms/stomp1.2/pom.xml +++ b/examples/jms/stomp1.2/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-stomp1.2-example + stomp1.2 jar ActiveMQ Artemis JMS Stomp 1.2 Example @@ -37,71 +38,81 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.StompExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-stomp1.2-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.StompExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + stomp1.2 + ${project.version} + + + + + diff --git a/examples/jms/stomp1.2/readme.html b/examples/jms/stomp1.2/readme.html index f8d94ee5b9..3661f049b1 100644 --- a/examples/jms/stomp1.2/readme.html +++ b/examples/jms/stomp1.2/readme.html @@ -27,112 +27,12 @@ under the License.

          Stomp 1.2 Example

          +
          To run the example, simply type mvn verify from this directory, 
          or mvn -PnoServer verify if you want to start and create the server manually.
          + +

          This example shows you how to configure ActiveMQ Artemis to send and receive Stomp messages using Stomp 1.2 protocol.

          The example will start a ActiveMQ Artemis server configured with Stomp and JMS.

          -

          The client will open a socket to initiate a Stomp 1.2 connection and then send one Stomp message (using TCP directly). +

          The client will open a socket to initiate a Stomp 1.2 connection and then send one Stomp message (using TCP directly). The client will then consume a message from a JMS Queue and check it is the message sent with Stomp.

          - -

          Example step-by-step

          -

          To run the example, simply type mvn verify -Pexample from this directory

          - -
            -
          1. We create a TCP socket to connect to the Stomp port -
            -          Socket socket = new Socket("localhost", 61613); 
            -        
            - -
          2. We negotiate a Stomp 1.2 connection to the server
          3. -
            -         String connectFrame = "CONNECT\n" + 
            -            "accept-version:1.1\n" +
            -            "host:localhost\n" +
            -            "login:guest\n" +
            -            "passcode:guest\n" +
            -            "request-id:1\n" +
            -            "\n" +
            -            END_OF_FRAME;
            -          sendFrame(socket, connectFrame);
            -        
            - -
          4. We receive a response showing that the connection version
          5. -
            -         String response = receiveFrame(socket);
            -         System.out.println("response: " + response);
            -        
            - -
          6. We send a SEND frame (a Stomp message) to the destination jms.queue.exampleQueue - (which corresponds to the ActiveMQ Artemis address for the JMS Queue exampleQueue) with a text body
          7. -
            -          String text = "Hello World from Stomp 1.2 !";
            -          String message = "SEND\n" + 
            -             "destination:jms.queue.exampleQueue\n" +
            -             "\n" +
            -             text +
            -             END_OF_FRAME;
            -          sendFrame(socket, message);
            -          System.out.println("Sent Stomp message: " + text);
            -        
            - -
          8. We send a DISCONNECT frame to disconnect from the server
          9. -
            -          String disconnectFrame = "DISCONNECT\n" +
            -             "\n" +
            -             Stomp.NULL;
            -          sendFrame(socket, disconnectFrame);
            -        
            - -
          10. We close the TCP socket
          11. -
            -          socket.close();
            -        
            - -
          12. We create an initial context to perform the JNDI lookup.
          13. -
            -          initialContext = getContext(0);
            -       
            - -
          14. We perform a lookup on the queue and the connection factory
          15. -
            -          Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue");
            -          ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
            -        
            - -
          16. We create a JMS Connection, Session and a MessageConsumer on the queue
          17. -
            -          connection = cf.createConnection();
            -          Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            -          MessageConsumer consumer = session.createConsumer(queue);
            -        
            - -
          18. We start the connection
          19. -
            -           connection.start();
            -        
            - -
          20. We receive the message. Stomp messages are mapped to JMS TextMessage.
          21. -
            -          TextMessage messageReceived = (TextMessage)consumer.receive(5000);
            -          System.out.println("Received JMS message: " + messageReceived.getText());
            -        
            - -
          22. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
          23. - -
            -           finally
            -           {
            -              if (initialContext != null)
            -              {
            -                initialContext.close();
            -              }
            -              if (connection != null)
            -              {
            -                 connection.close();
            -              }
            -           }
            -        
            - - - -
          diff --git a/examples/jms/stomp1.2/src/main/resources/activemq/server0/broker.xml b/examples/jms/stomp1.2/src/main/resources/activemq/server0/broker.xml index 9688ae9824..fea1cca2b6 100644 --- a/examples/jms/stomp1.2/src/main/resources/activemq/server0/broker.xml +++ b/examples/jms/stomp1.2/src/main/resources/activemq/server0/broker.xml @@ -29,13 +29,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/stop-server-failover/pom.xml b/examples/jms/stop-server-failover/pom.xml index 2ba5e695c6..0a1a9faee2 100644 --- a/examples/jms/stop-server-failover/pom.xml +++ b/examples/jms/stop-server-failover/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-stop-server-failover-example + stop-server-failover jar ActiveMQ Artemis JMS Stop Server Failover Example @@ -37,121 +38,132 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create0 - - create - - - ${basedir}/target/server0 - true - false - ../data - true - - - - create1 - - create - - - ${basedir}/target/server1 - true - true - ../data - true - - - - start0 - - cli - - - true - ${basedir}/target/server0 - tcp://localhost:61616 - - run - - server0 - - - - start1 - - cli - - - true - ${basedir}/target/server1 - tcp://localhost:61617 - - run - - server1 - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.StopServerFailoverExample - - - - stop0 - - cli - - - ${basedir}/target/server0 - - stop - - - - - stop1 - - cli - - - ${basedir}/target/server1 - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-stop-server-failover-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create0 + + create + + + ${noServer} + ${basedir}/target/server0 + true + false + ../data + true + + + + create1 + + create + + + ${noServer} + ${basedir}/target/server1 + true + true + ../data + true + + + + start0 + + cli + + + ${noServer} + true + ${basedir}/target/server0 + tcp://localhost:61616 + + run + + server0 + + + + start1 + + cli + + + ${noServer} + true + ${basedir}/target/server1 + tcp://localhost:61617 + + run + + server1 + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.StopServerFailoverExample + + + + stop0 + + cli + + + ${noServer} + ${basedir}/target/server0 + + stop + + + + + stop1 + + cli + + + ${noServer} + ${basedir}/target/server1 + + stop + + + + + + + org.apache.activemq.examples.jms + stop-server-failover + ${project.version} + + + + + diff --git a/examples/jms/stop-server-failover/readme.html b/examples/jms/stop-server-failover/readme.html index 0e83d3733d..bea57559ba 100644 --- a/examples/jms/stop-server-failover/readme.html +++ b/examples/jms/stop-server-failover/readme.html @@ -26,130 +26,19 @@ under the License.

          JMS Failover Without Transactions Example

          - + +
          To run the example, simply type mvn verify from this directory, 
          or mvn -PnoServer verify if you want to start and create the server manually.
          + +

          This example demonstrates two servers coupled as a live-backup pair for high availability (HA), and a client connection failing over from live to backup when the live server is crashed.

          Failover behavior differs whether the JMS session is transacted or not.

          -

          When a non-transacted JMS session is used, once and only once delivery is not guaranteed +

          When a non-transacted JMS session is used, once and only once delivery is not guaranteed and it is possible some messages will be lost or delivered twice, depending when the failover to the backup server occurs.

          It is up to the client to deal with such cases. To ensure once and only once delivery, the client must use transacted JMS sessions (as shown in the example for failover with transactions).

          For more information on ActiveMQ Artemis failover and HA, and clustering in general, please see the clustering section of the user manual.

          -

          Example step-by-step

          -

          To run the example, simply type mvn verify -Pexample from this directory

          -

          In this example, the live server is server 1, and the backup server is server 0

          -

          The connection will initially be created to server1, server 1 will crash, and the client will carry on - seamlessly on server 0, the backup server.

          -
            -
          1. Get an initial context for looking up JNDI from server #1.
          2. -
            -           initialContext = getContext(1);
            -        
            - -
          3. Look up the JMS resources from JNDI on server #1.
          4. -
            -           Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue");
            -           ConnectionFactory connectionFactory = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
            -        
            - -
          5. Create a JMS Connection
          6. -
            -           connection = connectionFactory.createConnection();
            -        
            - -
          7. Create a JMS non-transacted Session with client acknowledgement
          8. -
            -           Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
            -        
            - -
          9. Start the connection to ensure delivery occurs
          10. -
            -           connection.start();
            -        
            - -
          11. Create a JMS MessageProducer and MessageConsumer
          12. -
            -           MessageProducer producer = session.createProducer(queue);
            -           MessageConsumer consumer = session.createConsumer(queue);
            -        
            - -
          13. Send some messages to server #1
          14. -
            -           for (int i = 0; i < numMessages; i++)
            -           {
            -              TextMessage message = session.createTextMessage("This is text message " + i);
            -              producer.send(message);
            -              System.out.println("Sent message: " + message.getText());
            -           }
            -        
            - -
          15. Receive and acknowledge half of the sent messages
          16. -
            -           TextMessage message0 = null;
            -           for (int i = 0; i < numMessages / 2; i++)
            -           {
            -              message0 = (TextMessage)consumer.receive(5000);
            -              System.out.println("Got message: " + message0.getText());
            -           }
            -           message0.acknowledge();
            -        
            - -
          17. Receive the second half of the sent messages but do not acknowledge them yet
          18. -
            -           for (int i = numMessages / 2; i < numMessages; i++)
            -           {
            -              message0 = (TextMessage)consumer.receive(5000);
            -              System.out.println("Got message: " + message0.getText());
            -           }
            -        
            - -
          19. Crash server #1, the live server, and wait a little while to make sure it has really crashed.
          20. -
            -           killServer(1);
            -           Thread.sleep(2000);
            -        
            - -
          21. Acknowledging the second half of the sent messages will fail as failover to the backup server has occurred
          22. -
            -           try
            -           {
            -              message0.acknowledge();
            -           }
            -           catch (JMSException e)
            -           {
            -              System.err.println("Got exception while acknowledging message: " + e.getMessage());
            -           }
            -        
            - -
          23. Consume again the second half of the messages againg. Note that they are not considered as redelivered
          24. -
            -           for (int i = numMessages / 2; i < numMessages; i++)
            -           {
            -              message0 = (TextMessage)consumer.receive(5000);
            -              System.out.printf("Got message: %s (redelivered?: %s)\n", message0.getText(), message0.getJMSRedelivered());
            -           }
            -           message0.acknowledge();
            -        
            - -
          25. And finally, always remember to close your resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
          26. - -
            -           finally
            -           {
            -              if (connection != null)
            -              {
            -                 connection.close();
            -              }
            -
            -              if (initialContext != null)
            -              {
            -                 initialContext.close();
            -              }
            -           }
            -        
            - -
          diff --git a/examples/jms/symmetric-cluster/pom.xml b/examples/jms/symmetric-cluster/pom.xml index d6ed18946c..f471314da6 100644 --- a/examples/jms/symmetric-cluster/pom.xml +++ b/examples/jms/symmetric-cluster/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-symmetric-cluster-example + symmetric-cluster jar ActiveMQ Artemis JMS Symmetric Cluster Example @@ -41,270 +42,288 @@ under the License. artemis-jms-client ${project.version} - - org.apache.geronimo.specs - geronimo-jms_2.0_spec - - example - - - - org.apache.activemq - artemis-maven-plugin - - - create0 - - create - - - ${basedir}/target/server0 - ${basedir}/target/classes/activemq/server0 - -Dudp-address=${udp-address} - - - - create1 - - create - - - ${basedir}/target/server1 - ${basedir}/target/classes/activemq/server1 - -Dudp-address=${udp-address} - - - - create2 - - create - - - ${basedir}/target/server2 - ${basedir}/target/classes/activemq/server2 - -Dudp-address=${udp-address} - - - - create3 - - create - - - ${basedir}/target/server3 - ${basedir}/target/classes/activemq/server3 - -Dudp-address=${udp-address} - - - - create4 - - create - - - ${basedir}/target/server4 - ${basedir}/target/classes/activemq/server4 - -Dudp-address=${udp-address} - - - - create5 - - create - - - ${basedir}/target/server5 - ${basedir}/target/classes/activemq/server5 - -Dudp-address=${udp-address} - - - - start0 - - cli - - - true - ${basedir}/target/server0 - tcp://localhost:61616 - - run - - server0 - - - - start1 - - cli - - - true - ${basedir}/target/server1 - tcp://localhost:61617 - - run - - server1 - - - - start2 - - cli - - - true - ${basedir}/target/server2 - tcp://localhost:61618 - - run - - server2 - - - - start3 - - cli - - - true - ${basedir}/target/server3 - tcp://localhost:61619 - - run - - server3 - - - - start4 - - cli - - - true - ${basedir}/target/server4 - tcp://localhost:61620 - - run - - server4 - - - - start5 - - cli - - - true - ${basedir}/target/server5 - tcp://localhost:61621 - - run - - server5 - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.SymmetricClusterExample - - - - stop0 - - cli - - - ${basedir}/target/server0 - - stop - - - - - stop1 - - cli - - - ${basedir}/target/server1 - - stop - - - - - stop2 - - cli - - - ${basedir}/target/server2 - - stop - - - - - stop3 - - cli - - - ${basedir}/target/server3 - - stop - - - - - stop4 - - cli - - - ${basedir}/target/server4 - - stop - - - - - stop5 - - cli - - - ${basedir}/target/server5 - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-symmetric-cluster-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create0 + + create + + + ${noSever} + ${basedir}/target/server0 + ${basedir}/target/classes/activemq/server0 + -Dudp-address=${udp-address} + + + + create1 + + create + + + ${noSever} + ${basedir}/target/server1 + ${basedir}/target/classes/activemq/server1 + -Dudp-address=${udp-address} + + + + create2 + + create + + + ${noSever} + ${basedir}/target/server2 + ${basedir}/target/classes/activemq/server2 + -Dudp-address=${udp-address} + + + + create3 + + create + + + ${noSever} + ${basedir}/target/server3 + ${basedir}/target/classes/activemq/server3 + -Dudp-address=${udp-address} + + + + create4 + + create + + + ${noSever} + ${basedir}/target/server4 + ${basedir}/target/classes/activemq/server4 + -Dudp-address=${udp-address} + + + + create5 + + create + + + ${noSever} + ${basedir}/target/server5 + ${basedir}/target/classes/activemq/server5 + -Dudp-address=${udp-address} + + + + start0 + + cli + + + ${noSever} + true + ${basedir}/target/server0 + tcp://localhost:61616 + + run + + server0 + + + + start1 + + cli + + + ${noSever} + true + ${basedir}/target/server1 + tcp://localhost:61617 + + run + + server1 + + + + start2 + + cli + + + ${noSever} + true + ${basedir}/target/server2 + tcp://localhost:61618 + + run + + server2 + + + + start3 + + cli + + + ${noSever} + true + ${basedir}/target/server3 + tcp://localhost:61619 + + run + + server3 + + + + start4 + + cli + + + ${noSever} + true + ${basedir}/target/server4 + tcp://localhost:61620 + + run + + server4 + + + + start5 + + cli + + + ${noSever} + true + ${basedir}/target/server5 + tcp://localhost:61621 + + run + + server5 + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.SymmetricClusterExample + + + + stop0 + + cli + + + ${noSever} + ${basedir}/target/server0 + + stop + + + + + stop1 + + cli + + + ${noSever} + ${basedir}/target/server1 + + stop + + + + + stop2 + + cli + + + ${noSever} + ${basedir}/target/server2 + + stop + + + + + stop3 + + cli + + + ${noSever} + ${basedir}/target/server3 + + stop + + + + + stop4 + + cli + + + ${noSever} + ${basedir}/target/server4 + + stop + + + + + stop5 + + cli + + + ${noSever} + ${basedir}/target/server5 + + stop + + + + + + + org.apache.activemq.examples.jms + symmetric-cluster + ${project.version} + + + + + diff --git a/examples/jms/symmetric-cluster/readme.html b/examples/jms/symmetric-cluster/readme.html index 8be9587f7d..dc8ebc211d 100644 --- a/examples/jms/symmetric-cluster/readme.html +++ b/examples/jms/symmetric-cluster/readme.html @@ -27,6 +27,9 @@ under the License.

          JMS Symmetric Cluster Example

          +
          To run the example, simply type mvn verify from this directory, 
          or mvn -PnoServer verify if you want to start and create the server manually.
          + +

          This examples demonstrates a symmetric cluster set-up with ActiveMQ Artemis.

          ActiveMQ Artemis has extremely flexible clustering which allows you to set-up servers in many different topologies.

          @@ -67,210 +70,5 @@ under the License. by consumers on different nodes.

          For more information on configuring ActiveMQ Artemis clustering in general, please see the clustering section of the user manual.

          -

          Example step-by-step

          -

          To run the example, simply type mvn verify -Pexample from this directory

          - -
            -
          1. We instantiate a connection factory directly, specifying the UDP address and port for discovering - the list of servers in the cluster. - We could use JNDI to look-up a connection factory, but we'd need to know the JNDI server host and port for the - specific server to do that, and that server might not be available at the time. By creating the - connection factory directly we avoid having to worry about a JNDI look-up. - In an app server environment you could use HA-JNDI to lookup from the clustered JNDI servers without - having to know about a specific one. -
          2. - -
            -           
            -   ConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithHA("231.7.7.7", 9876);
            -   
            -        
            - -
          3. Directly instantiate JMS Queue and Topic objects
          4. -
            -           
            -   Queue queue = new ActiveMQQueue("exampleQueue");
            -
            -   Topic topic = ActiveMQJMSClient.createActiveMQTopic("exampleTopic");
            -           
            -        
            - -
          5. We create six connections, they should be to different nodes of the cluster in a round-robin fashion - and start them.
          6. -
            -           
            -   connection0 = cf.createConnection();
            -
            -     connection1 = cf.createConnection();
            -
            -     connection2 = cf.createConnection();
            -
            -     connection3 = cf.createConnection();
            -
            -     connection4 = cf.createConnection();
            -
            -     connection5 = cf.createConnection();
            -
            -     connection0.start();
            -
            -     connection1.start();
            -
            -     connection2.start();
            -
            -     connection3.start();
            -
            -     connection4.start();
            -
            -     connection5.start();
            -           
            -        
            - -
          7. We create a session on each connection.
          8. -
            -           
            -     Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE);
            -
            -     Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
            -
            -     Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
            -
            -     Session session3 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE);
            -
            -     Session session4 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
            -
            -     Session session5 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
            -           
            -        
            - -
          9. We create a topic subscriber on each server.
          10. -
            -           
            -         MessageConsumer subscriber0 = session0.createConsumer(topic);
            -
            -         MessageConsumer subscriber1 = session1.createConsumer(topic);
            -
            -         MessageConsumer subscriber2 = session2.createConsumer(topic);
            -
            -         MessageConsumer subscriber3 = session3.createConsumer(topic);
            -
            -         MessageConsumer subscriber4 = session4.createConsumer(topic);
            -
            -         MessageConsumer subscriber5 = session5.createConsumer(topic);
            -           
            -        
            - -
          11. We create a queue consumer on server 0.
          12. -
            -          
            -   MessageConsumer consumer0 = session0.createConsumer(queue);
            -          
            -        
            - -
          13. We create an anonymous message producer on server 2.
          14. -
            -          
            -   MessageProducer producer2 = session2.createProducer(null);
            -          
            -        
            - -
          15. We send 500 messages each to the queue and topic.
          16. -
            -           
            -   final int numMessages = 500;
            -
            -   for (int i = 0; i < numMessages; i++)
            -   {
            -      TextMessage message1 = session2.createTextMessage("Topic message 1");
            -
            -      producer2.send(topic, message1);
            -
            -      TextMessage message2 = session2.createTextMessage("Queue message 1");
            -
            -      producer2.send(queue, message2);
            -   }
            -           
            -       
            -
          17. Verify all subscribers and consumer receive the messages.
          18. -
            -           
            -   for (int i = 0; i < numMessages; i++)
            -     {
            -        TextMessage received0 = (TextMessage)subscriber0.receive(5000);
            -
            -        if (received0 == null)
            -        {
            -           return false;
            -        }
            -
            -        TextMessage received1 = (TextMessage)subscriber1.receive(5000);
            -
            -        if (received1 == null)
            -        {
            -           return false;
            -        }
            -
            -        TextMessage received2 = (TextMessage)subscriber2.receive(5000);
            -
            -        if (received2 == null)
            -        {
            -           return false;
            -        }
            -
            -        TextMessage received3 = (TextMessage)subscriber3.receive(5000);
            -
            -        if (received3 == null)
            -        {
            -           return false;
            -        }
            -
            -        TextMessage received4 = (TextMessage)subscriber4.receive(5000);
            -
            -        if (received4 == null)
            -        {
            -           return false;
            -        }
            -
            -        TextMessage received5 = (TextMessage)subscriber5.receive(5000);
            -
            -        if (received5 == null)
            -        {
            -           return false;
            -        }
            -
            -        TextMessage received6 = (TextMessage)consumer0.receive(5000);
            -
            -        if (received6 == null)
            -        {
            -           return false;
            -        }
            -     }
            -           
            -        
            - -
          19. Be sure to close our resources!
          20. - -
            -           
            -   finally
            -   {
            -      if (connection0 != null)
            -      {
            -         connection0.close();
            -      }
            -
            -      if (connection1 != null)
            -      {
            -         connection1.close();
            -      }
            -
            -      if (connection2 != null)
            -      {
            -         connection2.close();
            -      }
            -   }
            -           
            -        
            - -
          diff --git a/examples/jms/symmetric-cluster/src/main/resources/activemq/server0/broker.xml b/examples/jms/symmetric-cluster/src/main/resources/activemq/server0/broker.xml index 9c672d7cb5..cd89de7310 100644 --- a/examples/jms/symmetric-cluster/src/main/resources/activemq/server0/broker.xml +++ b/examples/jms/symmetric-cluster/src/main/resources/activemq/server0/broker.xml @@ -30,13 +30,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/symmetric-cluster/src/main/resources/activemq/server1/broker.xml b/examples/jms/symmetric-cluster/src/main/resources/activemq/server1/broker.xml index f02759badf..d95a1cd134 100644 --- a/examples/jms/symmetric-cluster/src/main/resources/activemq/server1/broker.xml +++ b/examples/jms/symmetric-cluster/src/main/resources/activemq/server1/broker.xml @@ -30,13 +30,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/symmetric-cluster/src/main/resources/activemq/server2/broker.xml b/examples/jms/symmetric-cluster/src/main/resources/activemq/server2/broker.xml index a188e71827..ef006fd558 100644 --- a/examples/jms/symmetric-cluster/src/main/resources/activemq/server2/broker.xml +++ b/examples/jms/symmetric-cluster/src/main/resources/activemq/server2/broker.xml @@ -30,13 +30,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/symmetric-cluster/src/main/resources/activemq/server3/broker.xml b/examples/jms/symmetric-cluster/src/main/resources/activemq/server3/broker.xml index 43ab47c64f..a780aceaf9 100644 --- a/examples/jms/symmetric-cluster/src/main/resources/activemq/server3/broker.xml +++ b/examples/jms/symmetric-cluster/src/main/resources/activemq/server3/broker.xml @@ -30,13 +30,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/symmetric-cluster/src/main/resources/activemq/server4/broker.xml b/examples/jms/symmetric-cluster/src/main/resources/activemq/server4/broker.xml index ce4afab4ac..20b622e05f 100644 --- a/examples/jms/symmetric-cluster/src/main/resources/activemq/server4/broker.xml +++ b/examples/jms/symmetric-cluster/src/main/resources/activemq/server4/broker.xml @@ -30,13 +30,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/symmetric-cluster/src/main/resources/activemq/server5/broker.xml b/examples/jms/symmetric-cluster/src/main/resources/activemq/server5/broker.xml index d23612a37d..033af4370b 100644 --- a/examples/jms/symmetric-cluster/src/main/resources/activemq/server5/broker.xml +++ b/examples/jms/symmetric-cluster/src/main/resources/activemq/server5/broker.xml @@ -30,13 +30,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/temp-queue/pom.xml b/examples/jms/temp-queue/pom.xml index 1599fcc387..ef544e1eb7 100644 --- a/examples/jms/temp-queue/pom.xml +++ b/examples/jms/temp-queue/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-temp-queue-example + temp-queue jar ActiveMQ Artemis JMS Temporary Queue Example @@ -37,71 +38,81 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.TemporaryQueueExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-temp-queue-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.TemporaryQueueExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + temp-queue + ${project.version} + + + + + diff --git a/examples/jms/temp-queue/readme.html b/examples/jms/temp-queue/readme.html index 2685f31297..f1cae4d11d 100644 --- a/examples/jms/temp-queue/readme.html +++ b/examples/jms/temp-queue/readme.html @@ -27,136 +27,14 @@ under the License.

          JMS Temporary Queue Example

          +
          To run the example, simply type mvn verify from this directory, 
          or mvn -PnoServer verify if you want to start and create the server manually.
          + +

          This example shows you how to use a TemporaryQueue with ActiveMQ Artemis. First a temporary queue is created to send and receive a message and then deleted. Then another temporary queue is created and used after its connection is closed to illustrate its scope.

          A TemporaryQueue is a JMS queue that exists only within the lifetime of its connection. It is often used in request-reply type messaging where the reply is sent through a temporary destination. The temporary queue is often created as a server resource, so after using, the user should call delete() method to release the resources. Please consult the JMS 1.1 specification for full details.

          - -

          Example step-by-step

          -

          To run the example, simply type mvn verify -Pexample from this directory

          - -
            -
          1. First we need to get an initial context so we can look-up the JMS connection factory from JNDI. This initial context will get it's properties from the client-jndi.properties file in the directory ../common/config
          2. -
            -           initialContext = getContext();
            -        
            - -
          3. We look-up JMS connection factory from JNDI
          4. -
            -           ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
            -        
            - -
          5. We Create a JMS connection
          6. -
            -           connection = cf.createConnection();
            -        
            - -
          7. We start the connection. In order for delivery to occur on any consumers or subscribers on a connection, the connection must be started
          8. -
            -           connection.start();
            -        
            - -
          9. We create a JMS session. The session is created as non transacted and will auto acknowledge messages.
          10. -
            -           Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            -        
            - -
          11. We create a Temporary Queue
          12. -
            -           Queue tempQueue = session.createTemporaryQueue();
            -        
            - -
          13. We create a JMS message producer to the temporary queue. This will be used to send the messages.
          14. -
            -	        MessageProducer messageProducer = session.createProducer(tempQueue);
            -        
            - -
          15. We create a JMS text message to send
          16. -
            -           TextMessage message = session.createTextMessage("This is a text message");
            -        
            - -
          17. We send the message to the temporary queue
          18. -
            -           messageProducer.send(message);
            -        
            - -
          19. We create a message consumer of the temporary queue
          20. -
            -           MessageConsumer messageConsumer = session.createConsumer(tempQueue);
            -        
            - -
          21. We receive the message from the temporary queue
          22. -
            -           message = (TextMessage) messageConsumer.receive(5000);
            -        
            - -
          23. We close the consumer and producer before destroying the temporary queue
          24. -
            -           messageConsumer.close();
            -           messageProducer.close();
            -        
            - -
          25. We delete the temporary queue
          26. -
            -           tempQueue.delete();
            -        
            - -
          27. We create another temporary queue
          28. -
            -           TemporaryQueue tempQueue2 = session.createTemporaryQueue();
            -        
            - -
          29. We close the connection
          30. -
            -           connection.close();
            -        
            - -
          31. We create a new connection
          32. -
            -           connection = cf.createConnection();
            -        
            - -
          33. We create a new session
          34. -
            -           session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            -        
            - -
          35. We try to access the tempQueue2 outside its lifetime, this will cause exception thrown
          36. -
            -           
            -         try
            -         {
            -            messageConsumer = session.createConsumer(tempQueue2);
            -            throw new Exception("Temporary queue cannot be accessed outside its lifecycle!");
            -         }
            -         catch (InvalidDestinationException e)
            -         {
            -            System.out.println("Exception got when trying to access a temp queue outside its scope: " + e);
            -         }
            -           
            -        
            - -
          37. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
          38. - -
            -           finally
            -           {
            -              if (initialContext != null)
            -              {
            -                initialContext.close();
            -              }
            -              if (connection != null)
            -              {
            -                 connection.close();
            -              }
            -           }
            -        
            - - - -
          diff --git a/examples/jms/temp-queue/src/main/resources/activemq/server0/broker.xml b/examples/jms/temp-queue/src/main/resources/activemq/server0/broker.xml index f1c14b2db6..2dd2df9285 100644 --- a/examples/jms/temp-queue/src/main/resources/activemq/server0/broker.xml +++ b/examples/jms/temp-queue/src/main/resources/activemq/server0/broker.xml @@ -29,13 +29,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/topic-hierarchies/pom.xml b/examples/jms/topic-hierarchies/pom.xml index 250abd3aef..320e870382 100644 --- a/examples/jms/topic-hierarchies/pom.xml +++ b/examples/jms/topic-hierarchies/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-topic-hierarchies-example + topic-hierarchies jar ActiveMQ Artemis JMS Topic Hierarchies Example @@ -41,72 +42,77 @@ under the License. artemis-jms-client ${project.version} - - org.apache.geronimo.specs - geronimo-jms_2.0_spec - - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.TopicHierarchyExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-topic-hierarchies-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.TopicHierarchyExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + topic-hierarchies + ${project.version} + + + + + diff --git a/examples/jms/topic-hierarchies/readme.html b/examples/jms/topic-hierarchies/readme.html index d87cb1a425..c901d57e78 100644 --- a/examples/jms/topic-hierarchies/readme.html +++ b/examples/jms/topic-hierarchies/readme.html @@ -27,6 +27,9 @@ under the License.

          Topic Hierarchy Example

          +
          To run the example, simply type mvn verify from this directory, 
          or mvn -PnoServer verify if you want to start and create the server manually.
          + +

          ActiveMQ Artemis supports topic hierarchies. With a topic hierarchy you can register a subscriber with a wild-card and that subscriber will receive any messages routed to an address that match the wildcard.

          ActiveMQ Artemis wild-cards can use the character '#' which means "match any number of words", and @@ -35,166 +38,5 @@ under the License. "news.europe", "news.europe.sport" and "news.europe.entertainment", but it does not match messages sent to the address "news.usa.wrestling"

          For more information on the wild-card syntax please consult the user manual.

          -

          Example step-by-step

          -

          To run the example, simply type mvn verify -Pexample from this directory

          -

          In this example we will define a hierarchy of topics in the file activemq-jms.xml

          -
          -        
          -   <topic name="news">
          -      <entry name="/topic/news"/>
          -   </topic>
          -   
          -   <topic name="news.usa">
          -      <entry name="/topic/news.usa"/>
          -   </topic>
          -   
          -   <topic name="news.usa.wrestling">
          -      <entry name="/topic/news.wrestling"/>
          -   </topic>
          -   
          -   <topic name="news.europe">
          -      <entry name="/topic/news.europe"/>
          -   </topic>
          -   
          -   <topic name="news.europe.sport">
          -      <entry name="/topic/news.europe.sport"/>
          -   </topic>
          -   
          -   <topic name="news.europe.entertainment">
          -      <entry name="/topic/news.europe.entertainment"/>
          -   </topic>
          -        
          -     
          -

          Then we will create a subscriber using the wildcard "news.europe.#".

          -

          We will then send three messages: one to the address news.usa.wrestling, one to the address news.europe.sport, - and one to the address news.europe.entertainment.

          -

          We will verify that the message sent to news.usa.wrestling does not get received since it does not match, - but the messages sent to the other two addresses do get received since they match.

          - -
            -
          1. Create an initial context to perform the JNDI lookup.
          2. -
            -           initialContext = getContext(0);
            -        
            - -
          3. Perform a lookup on the Connection Factory
          4. -
            -           ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
            -        
            - -
          5. Create a JMS Connection
          6. -
            -           connection = cf.createConnection();
            -        
            - -
          7. Create a JMS Session
          8. -
            -           Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            -        
            - -
          9. Instantiate a topic representing the wildcard we're going to subscribe to.
          10. -
            -           Topic topicSubscribe = ActiveMQJMSClient.createActiveMQTopic("news.europe.#");
            -        
            - -
          11. Create a consumer (topic subscriber) that will consume using that wildcard. - The consumer will receive any messages sent to any topic that starts with news.europe
          12. -
            -          MessageConsumer messageConsumer = session.createConsumer(topicSubscribe);
            -       
            - -
          13. Create an anonymous producer. The sending address is specified at send time.
          14. -
            -           MessageProducer producer = session.createProducer(null);
            -        
            - -
          15. Instantiate some more topic objects corresponding to the individual topics - we're going to send messages to. You could look these up from JNDI if you wanted to.
          16. -
            -           
            -         Topic topicNewsUsaWrestling = ActiveMQJMSClient.createActiveMQTopic("news.usa.wrestling");
            -         
            -         Topic topicNewsEuropeSport = ActiveMQJMSClient.createActiveMQTopic("news.europe.sport");
            -         
            -         Topic topicNewsEuropeEntertainment = ActiveMQJMSClient.createActiveMQTopic("news.europe.entertainment");
            -        
            - -
          17. Send a message destined for the usa wrestling topic.
          18. -
            -           
            -         TextMessage messageWrestlingNews = session.createTextMessage("Hulk Hogan starts ballet classes");
            -         
            -         producer.send(topicNewsUsaWrestling, messageWrestlingNews);
            -           
            -        
            - -
          19. Send a message destined for the europe sport topic.
          20. -
            -           
            -         TextMessage messageEuropeSport = session.createTextMessage("Lewis Hamilton joins European synchronized swimming team");
            -         
            -         producer.send(topicNewsEuropeSport, messageEuropeSport);           
            -           
            -        
            - -
          21. Send a message destined for the europe entertainment topic
          22. -
            -           
            -         TextMessage messageEuropeEntertainment = session.createTextMessage("John Lennon resurrected from dead");
            -         
            -         producer.send(topicNewsEuropeEntertainment, messageEuropeEntertainment);
            -           
            -        
            - -
          23. Start the connection
          24. -
            -           
            -        connection.start();
            -           
            -        
            - -
          25. We don't receive the usa wrestling message since we subscribed to news.europe.# and - that doesn't match news.usa.wrestling. However we do receive the Europe sport message, and the - europe entertainment message, since these match the wildcard.
          26. -
            -           
            -        TextMessage messageReceived1 = (TextMessage)messageConsumer.receive(5000);
            -         
            -        System.out.println("Received message: " + messageReceived1.getText());
            -         
            -        TextMessage messageReceived2 = (TextMessage)messageConsumer.receive(5000);
            -         
            -        System.out.println("Received message: " + messageReceived2.getText());
            -         
            -        Message message = messageConsumer.receive(1000);
            -         
            -        if (message != null)
            -        {
            -           return false;
            -        }
            -         
            -        System.out.println("Didn't received any more message: " + message);
            -           
            -        
            - -
          27. Be sure to close our resources!
          28. - -
            -           finally
            -           {
            -              if (initialContext != null)
            -              {
            -                initialContext.close();
            -              }
            -              if (connection != null)
            -              {
            -                 connection.close();
            -              }
            -           }
            -        
            - - - -
          diff --git a/examples/jms/topic-hierarchies/src/main/resources/activemq/server0/broker.xml b/examples/jms/topic-hierarchies/src/main/resources/activemq/server0/broker.xml index ac065f6af4..9ec66c6f1e 100644 --- a/examples/jms/topic-hierarchies/src/main/resources/activemq/server0/broker.xml +++ b/examples/jms/topic-hierarchies/src/main/resources/activemq/server0/broker.xml @@ -40,13 +40,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/topic-selector-example1/pom.xml b/examples/jms/topic-selector-example1/pom.xml index bbf95ee9a6..01c528ab33 100644 --- a/examples/jms/topic-selector-example1/pom.xml +++ b/examples/jms/topic-selector-example1/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-topic-selector-example1-example + topic-selector1 jar ActiveMQ Artemis JMS Topic Selector Example 1 @@ -37,71 +38,81 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.TopicSelectorExample1 - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-topic-selector-example1-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.TopicSelectorExample1 + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + topic-selector1 + ${project.version} + + + + + diff --git a/examples/jms/topic-selector-example1/readme.html b/examples/jms/topic-selector-example1/readme.html index 630cd2b763..568185258f 100644 --- a/examples/jms/topic-selector-example1/readme.html +++ b/examples/jms/topic-selector-example1/readme.html @@ -27,153 +27,12 @@ under the License.

          JMS Topic Selector Example 1

          +
          To run the example, simply type mvn verify from this directory, 
          or mvn -PnoServer verify if you want to start and create the server manually.
          + +

          This example shows how messages can be consumed from a topic using Message Selectors.

          Consumers (or Subscribers) will only consume messages routed to a topic that match the provided selector

          Topics and selectors are a standard part of JMS, please consult the JMS 1.1 specification for full details.

          - -

          Example step-by-step

          -

          To run the example, simply type mvn verify -Pexample from this directory

          - -
            -
          1. First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the client-jndi.properties file in the directory ../common/config
          2. -
            -           initialContext = getContext();
            -        
            - -
          3. We look-up the JMS topic object from JNDI
          4. -
            -           Topic topic = (Topic) initialContext.lookup("/topic/exampleTopic");
            -        
            - -
          5. We look-up the JMS connection factory object from JNDI
          6. -
            -           ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
            -        
            - -
          7. We create a JMS connection
          8. -
            -           connection = cf.createConnection();
            -        
            - -
          9. We create a JMS session. The session is created as non transacted and will auto acknowledge messages.
          10. -
            -           Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            -        
            - -
          11. We create a JMS message producer on the session. This will be used to send the messages.
          12. -
            -          MessageProducer messageProducer = session.createProducer(topic);
            -        
            - -
          13. Create one non-durable subscriber with a specific filter
          14. -
            -         MessageConsumer messageConsumer1 = session.createConsumer(topic, "someID=1", false);
            -        
            - -
          15. Create a second non-durable subscriber with a specific filter
          16. -
            -         MessageConsumer messageConsumer2 = session.createConsumer(topic, "someID=2", false);
            -        
            - -
          17. Create a third non-durable subscriber without any filters, and it should receive the complete set of messages
          18. -
            -         MessageConsumer messageConsumer3 = session.createConsumer(topic, "someID=2", false);
            -        
            - -
          19. Send 20 messages, 10 with someID=1, 10 with someID=2
          20. -
            
            -         for (int i = 1; i < 10; i++)
            -         {
            -            for (int someID = 1; someID <= 2; someID++)
            -            {
            -               TextMessage message1 = session.createTextMessage("This is a text message " + i +
            -                                                                " sent for someID=" +
            -                                                                someID);
            -
            -               message1.setIntProperty("someID", someID);
            -
            -               producer.send(message1);
            -
            -               System.out.println("Sent message: " + message1.getText());
            -            }
            -         }
            - -
          21. We start the connection. In order for delivery to occur on any consumers or subscribers on a connection, the connection must be started
          22. -
                       connection.start();
            -        
            - - -
          23. Consume the messages from MessageConsumer1, filtering out someID=2
          24. -
            
            -         for (;;)
            -         {
            -            TextMessage messageReceivedA = (TextMessage)messageConsumer1.receive(1000);
            -            if (messageReceivedA == null)
            -            {
            -               break;
            -            }
            -
            -            System.out.println("messageConsumer1 received " + messageReceivedA.getText() +
            -                               " someID = " +
            -                               messageReceivedA.getIntProperty("someID"));
            -         }
            - -
          25. Consume the messages from MessageConsumer2, filtering out someID=1
          26. -
            
            -        for (;;)
            -         {
            -            TextMessage messageReceivedB = (TextMessage)messageConsumer2.receive(1000);
            -            if (messageReceivedB == null)
            -            {
            -               break;
            -            }
            -
            -            System.out.println("messageConsumer2 received " + messageReceivedB.getText() +
            -                               " someID = " +
            -                               messageReceivedB.getIntProperty("someID"));
            -         }
            - -
          27. Consume the messages from MessageConsumer3, receiving the complete set of messages
          28. -
            
            -         for (;;)
            -         {
            -            TextMessage messageReceivedC = (TextMessage)messageConsumer3.receive(1000);
            -            if (messageReceivedC == null)
            -            {
            -               break;
            -            }
            -            System.out.println("messageConsumer3 received " + messageReceivedC.getText() +
            -                               " someID = " +
            -                               messageReceivedC.getIntProperty("someID"));
            -         }
            - -
          29. Close the consumers
          30. -
            subscriberA.close();
            -
            subscriberB.close();
            - -
          31. Delete the subscriptions when you're done
          32. -
            session.unsubscribe("sub-a1");
            -
            session.unsubscribe("sub-a2");
            - -
          33. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
          34. - -
            -           finally
            -           {
            -              if (initialContext != null)
            -              {
            -                initialContext.close();
            -              }
            -              if (connection != null)
            -              {
            -                 connection.close();
            -              }
            -           }
            -        
            - - - -
          diff --git a/examples/jms/topic-selector-example1/src/main/resources/activemq/server0/broker.xml b/examples/jms/topic-selector-example1/src/main/resources/activemq/server0/broker.xml index 4a4b5056cf..d45eb5d9ef 100644 --- a/examples/jms/topic-selector-example1/src/main/resources/activemq/server0/broker.xml +++ b/examples/jms/topic-selector-example1/src/main/resources/activemq/server0/broker.xml @@ -29,13 +29,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/topic-selector-example2/pom.xml b/examples/jms/topic-selector-example2/pom.xml index b9f5332de0..cd23209581 100644 --- a/examples/jms/topic-selector-example2/pom.xml +++ b/examples/jms/topic-selector-example2/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-topic-selector-example2-example + topic-selector2 jar ActiveMQ Artemis JMS Topic Selector Example 2 @@ -37,71 +38,81 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.TopicSelectorExample2 - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-topic-selector-example2-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.TopicSelectorExample2 + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + topic-selector2 + ${project.version} + + + + + diff --git a/examples/jms/topic-selector-example2/readme.html b/examples/jms/topic-selector-example2/readme.html index 296281236b..8cb82c2216 100644 --- a/examples/jms/topic-selector-example2/readme.html +++ b/examples/jms/topic-selector-example2/readme.html @@ -27,131 +27,21 @@ under the License.

          JMS Topic Selector Example 2

          +
          To run the example, simply type mvn verify from this directory, 
          or mvn -PnoServer verify if you want to start and create the server manually.
          + +

          This example shows you how to selectively consume messages using message selectors with topic consumers.

          - +

          Message selectors are strings with special syntax that can be used in creating consumers. Message consumers that are thus created only receive messages that match its selector. On message delivering, the ActiveMQ Server evaluates the corresponding message headers of the messages against each selector, if any, and then delivers the 'matched' messages to its consumer. Please consult the JMS 1.1 specification for full details.

          - +

          In this example, three message consumers are created on a topic. The first consumer is created with selector 'color=red', it only receives messages that - have a 'color' string property of 'red' value; the second is created with selector 'color=green', it - only receives messages who have a 'color' string property of - 'green' value; and the third without a selector, which means it receives all messages. To illustrate, three messages + have a 'color' string property of 'red' value; the second is created with selector 'color=green', it + only receives messages who have a 'color' string property of + 'green' value; and the third without a selector, which means it receives all messages. To illustrate, three messages with different 'color' property values are created and sent.

          - -

          Example step-by-step

          -

          To run the example, simply type mvn verify -Pexample from this directory

          - -
            -
          1. First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the client-jndi.properties file in the directory ../common/config
          2. -
            -           InitialContext initialContext = getContext();
            -        
            - -
          3. We look-up the JMS topic object from JNDI
          4. -
            -           Topic topic = (Topic) initialContext.lookup("/topic/exampleTopic");
            -        
            - -
          5. We look-up the JMS connection factory object from JNDI
          6. -
            -           ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
            -        
            - -
          7. We create a JMS connection
          8. -
            -           connection = cf.createConnection();
            -        
            - -
          9. We start the connection
          10. -
            -           connection.start();
            -        
            - -
          11. We create a JMS session. The session is created as non transacted and will auto acknowledge messages.
          12. -
            -           Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            -        
            - -
          13. We create a JMS message producer on the session. This will be used to send the messages.
          14. -
            -          MessageProducer messageProducer = session.createProducer(topic);
            -       
            - -
          15. We create two selectors.
          16. -
            -           
            -           String redSelector = "color='red'";
            -           String greenSelector = "color='green'";
            -           
            -         
            - -
          17. We Create a JMS Message Consumer that receives 'red' messages.
          18. -
            -          
            -          MessageConsumer redConsumer = session.createConsumer(topic, redSelector);
            -          redConsumer.setMessageListener(new SimpleMessageListener("red"));
            -         
            -        
            - -
          19. We Create a second JMS Message Consumer that receives 'green' messages.
          20. -
            -          
            -          MessageConsumer greenConsumer = session.createConsumer(topic, greenSelector);
            -          greenConsumer.setMessageListener(new SimpleMessageListener("green"));
            -         
            -        
            - -
          21. We Create another JMS Message Consumer that receives all messages.
          22. -
            -          
            -          MessageConsumer allConsumer = session.createConsumer(topic);
            -          allConsumer.setMessageListener(new SimpleMessageListener("all"));
            -         
            -        
            - -
          23. We Create three messages, each has a different color property.
          24. -
            -           
            -           TextMessage redMessage = session.createTextMessage("Red");
            -           redMessage.setStringProperty("color", "red");
            -           TextMessage greenMessage = session.createTextMessage("Green");
            -           greenMessage.setStringProperty("color", "green");
            -           TextMessage blueMessage = session.createTextMessage("Blue");
            -           blueMessage.setStringProperty("color", "blue");
            -           
            -        
            - -
          25. We send the messages to the topic
          26. -
            -           
            -           producer.send(redMessage);
            -           System.out.println("Message sent: " + redMessage.getText());
            -           producer.send(greenMessage);
            -           System.out.println("Message sent: " + greenMessage.getText());
            -           producer.send(blueMessage);
            -           System.out.println("Message sent: " + blueMessage.getText());
            -           
            -        
            - -
          27. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
          28. - -
            -           finally
            -           {
            -              if (initialContext != null)
            -              {
            -                initialContext.close();
            -              }
            -              if (connection != null)
            -              {
            -                 connection.close();
            -              }
            -           }
            -        
            - -
          diff --git a/examples/jms/topic-selector-example2/src/main/resources/activemq/server0/broker.xml b/examples/jms/topic-selector-example2/src/main/resources/activemq/server0/broker.xml index 4a4b5056cf..d45eb5d9ef 100644 --- a/examples/jms/topic-selector-example2/src/main/resources/activemq/server0/broker.xml +++ b/examples/jms/topic-selector-example2/src/main/resources/activemq/server0/broker.xml @@ -29,13 +29,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/topic/pom.xml b/examples/jms/topic/pom.xml index 2c6a91a091..7e5005e852 100644 --- a/examples/jms/topic/pom.xml +++ b/examples/jms/topic/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-topic-example + topic jar ActiveMQ Artemis JMS Topic Example @@ -37,69 +38,80 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} + - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.TopicExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-topic-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.TopicExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + topic + ${project.version} + + + + + diff --git a/examples/jms/topic/readme.html b/examples/jms/topic/readme.html index 56b0a07f10..45358cbb7d 100644 --- a/examples/jms/topic/readme.html +++ b/examples/jms/topic/readme.html @@ -27,97 +27,10 @@ under the License.

          JMS Topic Example

          +
          To run the example, simply type mvn verify from this directory, 
          or mvn -PnoServer verify if you want to start and create the server manually.
          +

          This example shows you how to send and receive a message to a JMS Topic with ActiveMQ Artemis.

          Topics are a standard part of JMS, please consult the JMS 1.1 specification for full details.

          A Topic is used to send messages using the publish-subscribe model, from a producer to 1 or more consumers.

          - -

          Example step-by-step

          -

          To run the example, simply type mvn verify -Pexample from this directory

          - -
            -
          1. First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the client-jndi.properties file in the directory ../common/config
          2. -
            -           InitialContext initialContext = getContext();
            -        
            - -
          3. We look-up the JMS topic object from JNDI
          4. -
            -           Topic topic = (Topic) initialContext.lookup("/topic/exampleTopic");
            -        
            - -
          5. We look-up the JMS connection factory object from JNDI
          6. -
            -           ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
            -        
            - -
          7. We create a JMS connection
          8. -
            -           connection = cf.createConnection();
            -        
            - -
          9. We create a JMS session. The session is created as non transacted and will auto acknowledge messages.
          10. -
            -           Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            -        
            - -
          11. We create a JMS message producer on the session. This will be used to send the messages.
          12. -
            -          MessageProducer messageProducer = session.createProducer(topic);
            -       
            - -
          13. We create a JMS Message Consumer, messageConsumer1, to receive the message.
          14. -
            -           MessageConsumer messageConsumer = session.createConsumer(topic);
            -         
            - -
          15. We create a JMS Message Consumer, messageConsumer2, to also receive the message.
          16. -
            -          MessageConsumer messageConsumer2 = session.createConsumer(topic);
            -        
            - -
          17. We create a JMS text message that we are going to send.
          18. -
            -           TextMessage message = session.createTextMessage("This is a text message");
            -        
            - -
          19. We send message to the topic
          20. -
            -           messageProducer.send(message);
            -        
            - -
          21. We start the connection. In order for delivery to occur on any consumers or subscribers on a connection, the connection must be started
          22. -
            -           connection.start();
            -        
            - -
          23. The message arrives at the first consumer
          24. -
            -           TextMessage messageReceived = (TextMessage) messageConsumer1.receive();
            -        
            - -
          25. The message arrives at the second consumer
          26. -
            -           messageReceived = (TextMessage) messageConsumer2.receive();
            -        
            - -
          27. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
          28. - -
            -           finally
            -           {
            -              if (initialContext != null)
            -              {
            -                initialContext.close();
            -              }
            -              if (connection != null)
            -              {
            -                 connection.close();
            -              }
            -           }
            -        
            - - - -
          diff --git a/examples/jms/topic/src/main/resources/activemq/server0/broker.xml b/examples/jms/topic/src/main/resources/activemq/server0/broker.xml index f379d5533c..fd6671c1fa 100644 --- a/examples/jms/topic/src/main/resources/activemq/server0/broker.xml +++ b/examples/jms/topic/src/main/resources/activemq/server0/broker.xml @@ -29,13 +29,13 @@ under the License. - ${data.dir:./data}/bindings + ./data/bindings - ${data.dir:./data}/journal + ./data/journal - ${data.dir:./data}/largemessages + ./data/largemessages - ${data.dir:./data}/paging + ./data/paging diff --git a/examples/jms/transaction-failover/pom.xml b/examples/jms/transaction-failover/pom.xml index 0fe0ec87cd..d5bc653662 100644 --- a/examples/jms/transaction-failover/pom.xml +++ b/examples/jms/transaction-failover/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-transaction-failover-example + transaction-failover jar ActiveMQ Artemis JMS Transaction Failover Example @@ -47,62 +48,57 @@ under the License. - - - example - - - - org.apache.activemq - artemis-maven-plugin - - - create0 - - create - - - ${basedir}/target/server0 - ${basedir}/target/classes/activemq/server0 - -Dudp-address=${udp-address} - - - - create1 - - create - - - ${basedir}/target/server1 - ${basedir}/target/classes/activemq/server1 - -Dudp-address=${udp-address} - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.TransactionFailoverExample - - ${basedir}/target/server0 - ${basedir}/target/server1 - - - - - - - org.apache.activemq.examples.jms - artemis-jms-transaction-failover-example - ${project.version} - - - - - - - + + + + org.apache.activemq + artemis-maven-plugin + + + create0 + + create + + + ${basedir}/target/server0 + ${basedir}/target/classes/activemq/server0 + -Dudp-address=${udp-address} + + + + create1 + + create + + + ${basedir}/target/server1 + ${basedir}/target/classes/activemq/server1 + -Dudp-address=${udp-address} + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.TransactionFailoverExample + + ${basedir}/target/server0 + ${basedir}/target/server1 + + + + + + + org.apache.activemq.examples.jms + transaction-failover + ${project.version} + + + + + diff --git a/examples/jms/transaction-failover/readme.html b/examples/jms/transaction-failover/readme.html index f6b4c5d17c..5df44bd851 100644 --- a/examples/jms/transaction-failover/readme.html +++ b/examples/jms/transaction-failover/readme.html @@ -26,123 +26,21 @@ under the License.

          JMS Failover With Transaction Example

          - + +
          To run the example, simply type mvn verify from this directory.
          + +

          This example demonstrates two servers coupled as a live-backup pair for high availability (HA), and a client connection failing over from live to backup when the live server is crashed.

          Failover behavior differs whether the JMS session is transacter or not.

          When a transacted JMS session is used, once-and-only once delivery is guaranteed.

            -
          • if the failover occurs while there is an in-flight transaction, the transaction will be flagged as rollback only. In that case, the JMS client +
          • if the failover occurs while there is an in-flight transaction, the transaction will be flagged as rollback only. In that case, the JMS client will need to retry the transaction work.
          • if the failover occurs while there is no in-flight transaction, the failover will be transparent to the user.

          ActiveMQ Artemis also provides an example for non-transaction failover.

          For more information on ActiveMQ Artemis failover and HA, and clustering in general, please see the clustering section of the user manual.

          - -

          Example step-by-step

          -

          To run the example, simply type mvn verify -Pexample from this directory

          -

          In this example, the live server is server 1, and the backup server is server 0

          -

          The connection will initially be created to server1, server 1 will crash, and the client will carry on - seamlessly on server 0, the backup server.

          - -
            -
          1. Get an initial context for looking up JNDI from server #1.
          2. -
            -           initialContext = getContext(1);
            -        
            - -
          3. Look up the JMS resources from JNDI on server #1.
          4. -
            -           Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue");
            -           ConnectionFactory connectionFactory = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
            -        
            - -
          5. Create a JMS Connection
          6. -
            -           connection = connectionFactory.createConnection();
            -        
            - -
          7. Create a JMS transacted Session
          8. -
            -           Session session = connection.createSession(true, 0);
            -        
            - -
          9. Start the connection to ensure delivery occurs
          10. -
            -           connection.start();
            -        
            - -
          11. Create a JMS MessageProducer
          12. -
            -           MessageProducer producer = session.createProducer(queue);
            -        
            - -
          13. Create a JMS MessageConsumer
          14. -
            -           MessageConsumer consumer = session.createConsumer(queue);
            -        
            - -
          15. Send half of the messages, kill the live server and send the remaining messages
          16. -
            -           sendMessages(session, producer, numMessages, true);
            -        
            - -

            When server #1 crashes, the client automatically detects the failure and automatically - fails over from server #1 to server #0 (in your real program you wouldn't need to sleep). -

            - -
          17. As failover occurred during transaction, the session has been marked for rollback only and commit will fail
          18. -
            -           try
            -           {
            -              session.commit();
            -           } catch (TransactionRolledBackException e)
            -           {
            -              System.err.println("transaction has been rolled back: " + e.getMessage());
            -           }
            -        
            - -
          19. We resend all the messages
          20. -
            -           sendMessages(session, producer, numMessages, false);
            -        
            - -
          21. We commit the session successfully: the messages will be all delivered to the activated backup server
          22. -
            -           session.commit();
            -        
            - - -
          23. We are now transparently reconnected to server #0, the backup server. - We consume the messages sent before the crash of the live server, commit the session, and check there are no other message on the queue
          24. -
            -        for (int i = 0; i < numMessages; i++)
            -        {
            -           TextMessage message0 = (TextMessage)consumer.receive(5000);
            -           System.out.println("Got message: " + message0.getText());
            -        }
            -        session.commit();
            -        System.out.println("Other message on the server? " + consumer.receive(5000));
            -        
            - -
          25. And finally, always remember to close your resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
          26. - -
            -           finally
            -           {
            -              if (connection != null)
            -              {
            -                 connection.close();
            -              }
            -
            -              if (initialContext != null)
            -              {
            -                 initialContext.close();
            -              }
            -           }
            -        
            - -
          diff --git a/examples/jms/transactional/pom.xml b/examples/jms/transactional/pom.xml index 902912495f..82bde8a07c 100644 --- a/examples/jms/transactional/pom.xml +++ b/examples/jms/transactional/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-transactional-example + transactional jar ActiveMQ Artemis JMS Transactional Example @@ -37,71 +38,81 @@ under the License. - org.apache.geronimo.specs - geronimo-jms_2.0_spec + org.apache.activemq + artemis-jms-client + ${project.version} - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.TransactionalExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-transactional-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.TransactionalExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + transactional + ${project.version} + + + + + diff --git a/examples/jms/transactional/readme.html b/examples/jms/transactional/readme.html index a7517c5ae4..a988c27774 100644 --- a/examples/jms/transactional/readme.html +++ b/examples/jms/transactional/readme.html @@ -27,122 +27,14 @@ under the License.

          JMS Transactional Session Example

          +
          To run the example, simply type mvn verify from this directory, 
          or mvn -PnoServer verify if you want to start and create the server manually.
          + +

          This example shows you how to use a transacted Session with ActiveMQ Artemis.

          Firstly 2 messages are sent via the transacted sending session before being committed. This ensures that both message are sent

          Secondly the receiving session receives the messages firstly demonstrating a message being redelivered after the session being rolled back and then acknowledging receipt of the messages via the commit method.

          - -

          Example step-by-step

          -

          To run the example, simply type mvn verify -Pexample from this directory

          - -
            -
          1. First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the client-jndi.properties file in the directory ../common/config
          2. -
            -           initialContext = getContext();
            -        
            - -
          3. We look-up the JMS queue object from JNDI
          4. -
            -           Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");
            -        
            - -
          5. We look-up the JMS connection factory object from JNDI
          6. -
            -           ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
            -        
            - -
          7. We create a JMS connection
          8. -
            -           connection = cf.createConnection();
            -        
            - -
          9. We start the connection. In order for delivery to occur on any consumers or subscribers on a connection, the connection must be started
          10. -
            -           connection.start();
            -        
            - -
          11. We create a JMS session. The session is created as transacted.
          12. -
            -           Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
            -        
            - -
          13. We create a JMS message producer on the session. This will be used to send the messages.
          14. -
            -	   MessageProducer messageProducer = session.createProducer(queue);
            -        
            - -
          15. We create a message consumer
          16. -
            -	   MessageConsumer messageConsumer = session.createConsumer(queue);
            -        
            - -
          17. We create 2 text messages
          18. -
            -           TextMessage message1 = session.createTextMessage("This is a text message1");
            -           TextMessage message2 = session.createTextMessage("This is a text message2");
            -        
            - -
          19. We send the text messages to the queue
          20. -
            -           messageProducer.send(message1);
            -           messageProducer.send(message2);
            -        
            - -
          21. We receive the message, it will return null as the transaction is not committed.
          22. -
            -           TextMessage receivedMessage = (TextMessage) messageConsumer.receive(5000);
            -        
            - -
          23. We commit the session
          24. -
            -           session.commit();
            -        
            - -
          25. We receive the messages again
          26. -
            -           receivedMessage = (TextMessage) messageConsumer.receive(5000);
            -        
            - -
          27. We roll back the session, this will cause the received message canceled and redelivered again
          28. -
             
            -           session.rollback();
            -        
            - -
          29. We receive the message again, we will get two messages. Nothing more, nothing less
          30. -
             
            -           receivedMessage = (TextMessage) messageConsumer.receive(5000);
            -           receivedMessage = (TextMessage) messageConsumer.receive(5000);
            -        
            - -
          31. We commit the session
          32. -
             
            -           session.commit();
            -        
            - -
          33. We receive the message again. Nothing should be received
          34. -
             
            -           receivedMessage = (TextMessage) messageConsumer.receive(5000);
            -        
            - - -
          35. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
          36. - -
            -           finally
            -           {
            -              if (initialContext != null)
            -              {
            -                initialContext.close();
            -              }
            -              if (connection != null)
            -              {
            -                 connection.close();
            -              }
            -           }
            -        
            - -
          diff --git a/examples/jms/xa-heuristic/pom.xml b/examples/jms/xa-heuristic/pom.xml index ada7aafe11..3ea0740534 100644 --- a/examples/jms/xa-heuristic/pom.xml +++ b/examples/jms/xa-heuristic/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-xa-heuristic-example + xa-heuristic jar ActiveMQ Artemis JMS XAHeuristicExample Example @@ -38,83 +39,83 @@ under the License. org.apache.activemq - artemis-core-client + artemis-jms-client ${project.version} - - org.apache.activemq - artemis-commons - ${project.version} - - - org.apache.geronimo.specs - geronimo-jms_2.0_spec - - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=3001 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.XAHeuristicExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-xa-heuristic-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=3001 + -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false + + ${noServer} + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.XAHeuristicExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + xa-heuristic + ${project.version} + + + + + diff --git a/examples/jms/xa-heuristic/readme.html b/examples/jms/xa-heuristic/readme.html index 9ca84b0f16..c026defc91 100644 --- a/examples/jms/xa-heuristic/readme.html +++ b/examples/jms/xa-heuristic/readme.html @@ -26,222 +26,23 @@ under the License.

          JMS XA Heuristic Example

          + +
          To run the example, simply type mvn verify from this directory, 
          or mvn -PnoServer verify if you want to start and create the server manually.
          +

          This example shows you how to make an XA heuristic decision through the ActiveMQ Artemis Management Interface.

          - -

          A heuristic decision is a unilateral decision to commit or rollback an XA transaction branch after it has + +

          A heuristic decision is a unilateral decision to commit or rollback an XA transaction branch after it has been prepared.

          - +

          In this example we simulate a transaction manager to control the transactions. First we create an XASession and enlist it in a transaction through its XAResource. We then send a text message, 'hello' and end/prepare the transaction on the XAResource, but neither commit nor roll back the transaction. Another transaction is created and associated with the same XAResource, and a second message, 'world' is sent on behalf of the second transaction. Again we leave - the second transaction in prepare state. - Then we get the MBeanServerConnection object to manipulate the prepared transactions. To illustrate, we roll back the first + the second transaction in prepare state. + Then we get the MBeanServerConnection object to manipulate the prepared transactions. To illustrate, we roll back the first transaction but commit the second. This will result in that only the message 'world' is received.

          This example uses JMX to manipulate transactions in a ActiveMQ Artemis Server. For details on JMX facilities with ActiveMQ Artemis, please look at the JMX Example.

          - -

          Example step-by-step

          -

          To run the example, simply type mvn verify -Pexample from this directory

          -
            -
          1. First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the client-jndi.properties file in the directory ../common/config
          2. -
            -           InitialContext initialContext = getContext(0);
            -        
            - -
          3. We look-up the JMS queue object from JNDI
          4. -
            -           Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");
            -        
            - -
          5. We perform a lookup on the XA Connection Factory
          6. -
            -           XAConnectionFactory cf = (XAConnectionFactory) initialContext.lookup("/XAConnectionFactory");
            -        
            - -
          7. We create a JMS XAConnection
          8. -
            -           connection = cf.createXAConnection();
            -        
            - -
          9. We Start the connection
          10. -
            -           connection.start();
            -        
            - -
          11. We create a JMS XASession
          12. -
            -          XASession xaSession = connection.createXASession();
            -       
            - -
          13. We create a normal session
          14. -
            -          Session normalSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            -       
            - -
          15. We create a normal Message Consumer
          16. -
            -           
            -           MessageConsumer normalConsumer = normalSession.createConsumer(queue);
            -           normalConsumer.setMessageListener(new SimpleMessageListener());
            -           
            -       
            - -
          17. We get the JMS Session
          18. -
            -          Session session = xaSession.getSession();
            -       
            - -
          19. We create a message producer
          20. -
            -          MessageProducer producer = session.createProducer(queue); 
            -       
            - -
          21. We create two Text Messages
          22. -
            -          
            -          TextMessage helloMessage = session.createTextMessage("hello");
            -          TextMessage worldMessage = session.createTextMessage("world");
            -          
            -       
            - -
          23. We create a transaction
          24. -
            -          Xid xid1 = new XidImpl("xa-example1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
            -       
            - -
          25. We get the JMS XAResource
          26. -
            -          XAResource xaRes = xaSession.getXAResource();
            -       
            - -
          27. We begin the Transaction work
          28. -
            -          xaRes.start(xid1, XAResource.TMNOFLAGS);
            -       
            - -
          29. We do work, sending hello message.
          30. -
            -          
            -          normalProducer.send(helloMessage);
            -          
            -       
            - -
          31. We stop the work for xid1
          32. -
            -          xaRes.end(xid1, XAResource.TMSUCCESS);
            -       
            - -
          33. We prepare xid1
          34. -
            -          xaRes.prepare(xid1);
            -       
            - -
          35. We check the none should be received.
          36. -
            -          checkNoMessageReceived();
            -       
            - -
          37. We create another transaction
          38. -
            -          Xid xid2 = new XidImpl("xa-example2".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
            -       
            - -
          39. We begin the transaction work
          40. -
            -          xaRes.start(xid2, XAResource.TMNOFLAGS);
            -       
            - -
          41. We send the second message
          42. -
            -           producer.send(worldMessage);
            -       
            - -
          43. We stop the work for xid2
          44. -
            -          xaRes.end(xid2, XAResource.TMSUCCESS);
            -       
            - -
          45. We prepare xid2
          46. -
            -          xaRes.prepare(xid2);
            -       
            - -
          47. Again, no messages should be received!
          48. -
            -          checkNoMessageReceived();
            -       
            - -
          49. We create JMX Connector to connect to the server's MBeanServer.
          50. -
            -          
            -          JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(JMX_URL), new HashMap());
            -          
            -       
            - -
          51. We retrieve the MBeanServerConnection
          52. -
            -          MBeanServerConnection mbsc = connector.getMBeanServerConnection();
            -       
            - -
          53. We list the prepared transactions
          54. -
            -          
            -          ObjectName serverObject = ObjectNameBuilder.DEFAULT.getMessagingServerObjectName();
            -          String[] infos = (String[])mbsc.invoke(serverObject, "listPreparedTransactions", null, null);
            -         
            -          System.out.println("Prepared transactions: ");
            -          for (String i : infos)
            -          {
            -             System.out.println(i);
            -          }
            -          
            -       
            - -
          55. We roll back the first transaction
          56. -
            -          mbsc.invoke(serverObject, "rollbackPreparedTransaction", new String[] {XidImpl.toBase64String(xid1)}, new String[]{"java.lang.String"});
            -       
            - -
          57. We commit the second one
          58. -
            -          mbsc.invoke(serverObject, "commitPreparedTransaction", new String[] {XidImpl.toBase64String(xid2)}, new String[]{"java.lang.String"});
            -       
            - -
          59. We check the result, only the 'world' message received
          60. -
            -          checkMessageReceived("world");
            -       
            - -
          61. We check the prepared transaction again, should have none.
          62. -
            -          
            -          infos = (String[])mbsc.invoke(serverObject, "listPreparedTransactions", null, null);
            -          System.out.println("No. of prepared transactions now: " + infos.length);
            -          
            -       
            - -
          63. We close the JMX connector.
          64. -
            -          connector.close();
            -       
            - -
          65. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
          66. - -
            -           finally
            -           {
            -              if (initialContext != null)
            -              {
            -                initialContext.close();
            -              }
            -              if (connection != null)
            -              {
            -                 connection.close();
            -              }
            -           }
            -        
            -
          diff --git a/examples/jms/xa-receive/pom.xml b/examples/jms/xa-receive/pom.xml index 8336c5f9e6..c7b7da8e01 100644 --- a/examples/jms/xa-receive/pom.xml +++ b/examples/jms/xa-receive/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-xa-receive-example + xa-receive jar ActiveMQ Artemis JMS XA Receive Example @@ -38,76 +39,80 @@ under the License. org.apache.activemq - artemis-commons + artemis-jms-client ${project.version} - - org.apache.geronimo.specs - geronimo-jms_2.0_spec - - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.XAReceiveExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-xa-receive-example - ${project.version} - - - - - + + noServer + + true + - + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.XAReceiveExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + xa-receive + ${project.version} + + + + + diff --git a/examples/jms/xa-receive/readme.html b/examples/jms/xa-receive/readme.html index 0d24cde85c..47f2fefb11 100644 --- a/examples/jms/xa-receive/readme.html +++ b/examples/jms/xa-receive/readme.html @@ -26,197 +26,23 @@ under the License.

          JMS XA Receive Example

          + +
          To run the example, simply type mvn verify from this directory, 
          or mvn -PnoServer verify if you want to start and create the server manually.
          + +

          This example demonstrates receiving a message within the scope of an XA transaction. When using an XA transaction the message will only be acknowledged and removed from the queue when the transaction is committed. If the transaction is not committed the message maybe redelivered after rollback or during XA recovery.

          - +

          ActiveMQ Artemis is JTA aware, meaning you can use ActiveMQ Artemis in an XA transactional environment and participate in XA transactions. It provides the javax.transaction.xa.XAResource interface for that purpose. Users can get a XAConnectionFactory to create XAConnections and XASessions.

          - +

          In this example we simulate a transaction manager to control the transactions. First we create an XASession for receiving and a normal session for sending. Then we start a new xa transaction and enlist the receiving - XASession through its XAResource. We then send two words, 'hello' and 'world', receive them, and let the + XASession through its XAResource. We then send two words, 'hello' and 'world', receive them, and let the transaction roll back. The received messages are cancelled back to the queue. Next we start - a new transaction with the same XAResource enlisted, but this time we commit the transaction after receiving the + a new transaction with the same XAResource enlisted, but this time we commit the transaction after receiving the messages. Then we check that no more messages are to be received.

          - -

          Example step-by-step

          -

          To run the example, simply type mvn verify -Pexample from this directory

          -
            -
          1. First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the client-jndi.properties file in the directory ../common/config
          2. -
            -           InitialContext initialContext = getContext(0);
            -        
            - -
          3. We look-up the JMS queue object from JNDI
          4. -
            -           Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");
            -        
            - -
          5. We perform a lookup on the XA Connection Factory
          6. -
            -           XAConnectionFactory cf = (XAConnectionFactory) initialContext.lookup("/XAConnectionFactory");
            -        
            - -
          7. We create a JMS XAConnection
          8. -
            -           connection = cf.createXAConnection();
            -        
            - -
          9. We Start the connection
          10. -
            -           connection.start();
            -        
            - -
          11. We create a JMS XASession
          12. -
            -          XASession xaSession = connection.createXASession();
            -       
            - -
          13. We create a normal session
          14. -
            -          Session normalSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            -       
            - -
          15. We create a normal Message Producer
          16. -
            -           
            -           MessageProducer normalProducer = normalSession.createProducer(queue);
            -           
            -       
            - -
          17. We get the JMS Session
          18. -
            -          Session session = xaSession.getSession();
            -       
            - -
          19. We create a message consumer
          20. -
            -          MessageConsumer xaConsumer = session.createConsumer(queue); 
            -       
            - -
          21. We create two Text Messages
          22. -
            -          
            -          TextMessage helloMessage = session.createTextMessage("hello");
            -          TextMessage worldMessage = session.createTextMessage("world");
            -          
            -       
            - -
          23. We create a transaction
          24. -
            -          Xid xid1 = new XidImpl("xa-example1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
            -       
            - -
          25. We get the JMS XAResource
          26. -
            -          XAResource xaRes = xaSession.getXAResource();
            -       
            - -
          27. We begin the Transaction work
          28. -
            -          xaRes.start(xid1, XAResource.TMNOFLAGS);
            -       
            - -
          29. We send two messages.
          30. -
            -          
            -         normalProducer.send(helloMessage);
            -         normalProducer.send(worldMessage);
            -          
            -       
            - -
          31. We receive the messages
          32. -
            -          
            -          TextMessage rm1 = (TextMessage)xaConsumer.receive();
            -          System.out.println("Message received: " + rm1.getText());
            -          TextMessage rm2 = (TextMessage)xaConsumer.receive();
            -          System.out.println("Message received: " + rm2.getText());
            -          
            -       
            - -
          33. We stop the work
          34. -
            -          xaRes.end(xid1, XAResource.TMSUCCESS);
            -       
            - -
          35. We prepare
          36. -
            -          xaRes.prepare(xid1);
            -       
            - -
          37. We roll back the transaction
          38. -
            -          xaRes.rollback(xid1);
            -       
            - -
          39. We create another transaction
          40. -
            -          Xid xid2 = new XidImpl("xa-example2".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
            -       
            - -
          41. We start the transaction
          42. -
            -          xaRes.start(xid2, XAResource.TMNOFLAGS);
            -       
            - -
          43. We receive those messages again
          44. -
            -           
            -           rm1 = (TextMessage)xaConsumer.receive();
            -           System.out.println("Message received again: " + rm1.getText());
            -           rm2 = (TextMessage)xaConsumer.receive();
            -           System.out.println("Message received again: " + rm2.getText());
            -            
            -       
            - -
          45. We stop the work
          46. -
            -          xaRes.end(xid2, XAResource.TMSUCCESS);
            -       
            - -
          47. We prepare
          48. -
            -          xaRes.prepare(xid2);
            -       
            - -
          49. We commit!
          50. -
            -          xaRes.commit(xid2, false);
            -       
            - -
          51. We check that no more messages are received.
          52. -
            -          
            -          TextMessage rm3 = (TextMessage)xaConsumer.receive(2000);
            -          if (rm3 == null)
            -          {
            -             System.out.println("No message received after commit.");
            -          }
            -          else
            -          {
            -             result = false;
            -          }
            -          
            -       
            - -
          53. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
          54. - -
            -           finally
            -           {
            -              if (initialContext != null)
            -              {
            -                initialContext.close();
            -              }
            -              if (connection != null)
            -              {
            -                 connection.close();
            -              }
            -           }
            -        
            -
          diff --git a/examples/jms/xa-send/pom.xml b/examples/jms/xa-send/pom.xml index 3038202e98..cc6ab8f923 100644 --- a/examples/jms/xa-send/pom.xml +++ b/examples/jms/xa-send/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> - + 4.0.0 @@ -27,7 +28,7 @@ under the License. 1.0.1-SNAPSHOT - artemis-jms-xa-send-example + xa-send jar ActiveMQ Artemis JMS XA Send Example @@ -38,74 +39,80 @@ under the License. org.apache.activemq - artemis-commons + artemis-jms-client ${project.version} - - org.apache.geronimo.specs - geronimo-jms_2.0_spec - - example - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - - start - - cli - - - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.XASendExample - - - - stop - - cli - - - - stop - - - - - - - org.apache.activemq.examples.jms - artemis-jms-xa-send-example - ${project.version} - - - - - + + noServer + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.XASendExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.jms + xa-send + ${project.version} + + + + + + diff --git a/examples/pom.xml b/examples/pom.xml index 1371354ea1..456023a57b 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -60,6 +60,7 @@ under the License. + core jms diff --git a/pom.xml b/pom.xml index 28d48efb6c..f11c018a50 100644 --- a/pom.xml +++ b/pom.xml @@ -563,7 +563,6 @@ integration/activemq-spring-integration integration/activemq-aerogear-integration integration/activemq-vertx-integration - examples tests artemis-distribution