[
https://issues.apache.org/jira/browse/ARTEMIS-3365?focusedWorklogId=634621&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-634621
]
ASF GitHub Bot logged work on ARTEMIS-3365:
-------------------------------------------
Author: ASF GitHub Bot
Created on: 05/Aug/21 15:08
Start Date: 05/Aug/21 15:08
Worklog Time Spent: 10m
Work Description: brusdev commented on a change in pull request #3634:
URL: https://github.com/apache/activemq-artemis/pull/3634#discussion_r683543702
##########
File path: examples/features/broker-balancer/evenly-redirect/readme.md
##########
@@ -0,0 +1,6 @@
+# Evenly Redirect Example
+
+To run the example, simply type **mvn verify** from this directory, or **mvn
-PnoServer verify** if you want to create and start the broker manually.
+
+This example demonstrates how incoming client connections are evenly
redirected across two brokers
+using a third broker with a broker balancer to redirect incoming client
connections.
Review comment:
yes I would need a persistent cache to get Durable Subscription after a
restart
##########
File path:
examples/features/broker-balancer/evenly-redirect/src/main/java/org/apache/activemq/artemis/jms/example/EvenlyRedirectExample.java
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.artemis.jms.client.ActiveMQConnectionFactory;
+
+/**
+ * This example demonstrates how incoming client connections are evenly
redirected across two brokers
+ * using a third broker with a broker balancer to redirect incoming client
connections.
+ */
+public class EvenlyRedirectExample {
+
+ public static void main(final String[] args) throws Exception {
+
+ /**
+ * Step 1. Create a connection for producer0 and producer1, and send a
few messages.
+ * the server0 will redirect the connection of each producer to a
different target brokers.
+ */
+ ConnectionFactory connectionFactoryProducer0 = new
ActiveMQConnectionFactory("tcp://localhost:61616?ha=true&reconnectAttempts=30&clientID=FOO_PRODUCER");
+ ConnectionFactory connectionFactoryProducer1 = new
ActiveMQConnectionFactory("tcp://localhost:61616?ha=true&reconnectAttempts=30&clientID=TOO_PRODUCER");
Review comment:
updated
##########
File path:
examples/features/broker-balancer/evenly-redirect/src/main/java/org/apache/activemq/artemis/jms/example/EvenlyRedirectExample.java
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.artemis.jms.client.ActiveMQConnectionFactory;
+
+/**
+ * This example demonstrates how incoming client connections are evenly
redirected across two brokers
+ * using a third broker with a broker balancer to redirect incoming client
connections.
+ */
+public class EvenlyRedirectExample {
+
+ public static void main(final String[] args) throws Exception {
+
+ /**
+ * Step 1. Create a connection for producer0 and producer1, and send a
few messages.
+ * the server0 will redirect the connection of each producer to a
different target brokers.
+ */
+ ConnectionFactory connectionFactoryProducer0 = new
ActiveMQConnectionFactory("tcp://localhost:61616?ha=true&reconnectAttempts=30&clientID=FOO_PRODUCER");
+ ConnectionFactory connectionFactoryProducer1 = new
ActiveMQConnectionFactory("tcp://localhost:61616?ha=true&reconnectAttempts=30&clientID=TOO_PRODUCER");
+
+ Connection connectionProducer0 = null;
+ Connection connectionProducer1 = null;
+
+ try {
+ connectionProducer0 = connectionFactoryProducer0.createConnection();
+ connectionProducer1 = connectionFactoryProducer1.createConnection();
+
+ for (Connection connectionProducer : new Connection[]
{connectionProducer0, connectionProducer1}) {
+ Session session = connectionProducer.createSession(false,
Session.AUTO_ACKNOWLEDGE);
+
+ Queue queue = session.createQueue("exampleQueue");
+ MessageProducer sender = session.createProducer(queue);
+ for (int i = 0; i < 100; i++) {
+ sender.send(session.createTextMessage("Hello world n" + i + " -
" + connectionProducer.getClientID()));
+ }
+ }
+ } finally {
+ if (connectionProducer0 != null) {
+ connectionProducer0.close();
+ }
+
+ if (connectionProducer1 != null) {
+ connectionProducer1.close();
+ }
+ }
+
+ /**
+ * Step 2. create a connection for consumer0 and consumer1, and receive
a few messages.
+ * the server0 will redirect the connection to the same target broker of
the respective producer
+ * because the consumer and the producer share the same clientID prefix.
Review comment:
updated
##########
File path:
examples/features/broker-balancer/evenly-redirect/src/main/java/org/apache/activemq/artemis/jms/example/EvenlyRedirectExample.java
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.artemis.jms.client.ActiveMQConnectionFactory;
+
+/**
+ * This example demonstrates how incoming client connections are evenly
redirected across two brokers
+ * using a third broker with a broker balancer to redirect incoming client
connections.
+ */
+public class EvenlyRedirectExample {
+
+ public static void main(final String[] args) throws Exception {
+
+ /**
+ * Step 1. Create a connection for producer0 and producer1, and send a
few messages.
+ * the server0 will redirect the connection of each producer to a
different target brokers.
+ */
+ ConnectionFactory connectionFactoryProducer0 = new
ActiveMQConnectionFactory("tcp://localhost:61616?ha=true&reconnectAttempts=30&clientID=FOO_PRODUCER");
+ ConnectionFactory connectionFactoryProducer1 = new
ActiveMQConnectionFactory("tcp://localhost:61616?ha=true&reconnectAttempts=30&clientID=TOO_PRODUCER");
+
+ Connection connectionProducer0 = null;
+ Connection connectionProducer1 = null;
+
+ try {
+ connectionProducer0 = connectionFactoryProducer0.createConnection();
+ connectionProducer1 = connectionFactoryProducer1.createConnection();
+
+ for (Connection connectionProducer : new Connection[]
{connectionProducer0, connectionProducer1}) {
+ Session session = connectionProducer.createSession(false,
Session.AUTO_ACKNOWLEDGE);
+
+ Queue queue = session.createQueue("exampleQueue");
+ MessageProducer sender = session.createProducer(queue);
+ for (int i = 0; i < 100; i++) {
+ sender.send(session.createTextMessage("Hello world n" + i + " -
" + connectionProducer.getClientID()));
+ }
+ }
+ } finally {
+ if (connectionProducer0 != null) {
+ connectionProducer0.close();
+ }
+
+ if (connectionProducer1 != null) {
+ connectionProducer1.close();
+ }
+ }
+
+ /**
+ * Step 2. create a connection for consumer0 and consumer1, and receive
a few messages.
+ * the server0 will redirect the connection to the same target broker of
the respective producer
+ * because the consumer and the producer share the same clientID prefix.
+ */
+ ConnectionFactory connectionFactoryConsumer0 = new
ActiveMQConnectionFactory("tcp://localhost:61616?ha=true&reconnectAttempts=30&clientID=TOO_CONSUMER");
+ ConnectionFactory connectionFactoryConsumer1 = new
ActiveMQConnectionFactory("tcp://localhost:61616?ha=true&reconnectAttempts=30&clientID=FOO_CONSUMER");
Review comment:
updated
##########
File path:
examples/features/broker-balancer/symmetric-redirect/src/main/java/org/apache/activemq/artemis/jms/example/SymmetricRedirectExample.java
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.artemis.jms.client.ActiveMQConnectionFactory;
+
+/**
+ * This example demonstrates how incoming client connections are distributed
across two brokers
+ * using a symmetric architecture.
+ */
+public class SymmetricRedirectExample {
+
+ public static void main(final String[] args) throws Exception {
+
+ /**
+ * Step 1. Create a connection for producer0 and producer1, and send a
few messages.
+ * the server0 will redirect the connection of each producer to a
different target brokers.
+ */
+ ConnectionFactory connectionFactory0Server0 = new
ActiveMQConnectionFactory("tcp://localhost:61616?ha=true&reconnectAttempts=30&clientID=FOO_PRODUCER");
+ ConnectionFactory connectionFactory1Server0 = new
ActiveMQConnectionFactory("tcp://localhost:61616?ha=true&reconnectAttempts=30&clientID=TOO_PRODUCER");
Review comment:
updated
##########
File path:
examples/features/broker-balancer/symmetric-redirect/src/main/java/org/apache/activemq/artemis/jms/example/SymmetricRedirectExample.java
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.artemis.jms.client.ActiveMQConnectionFactory;
+
+/**
+ * This example demonstrates how incoming client connections are distributed
across two brokers
+ * using a symmetric architecture.
+ */
+public class SymmetricRedirectExample {
+
+ public static void main(final String[] args) throws Exception {
+
+ /**
+ * Step 1. Create a connection for producer0 and producer1, and send a
few messages.
+ * the server0 will redirect the connection of each producer to a
different target brokers.
+ */
+ ConnectionFactory connectionFactory0Server0 = new
ActiveMQConnectionFactory("tcp://localhost:61616?ha=true&reconnectAttempts=30&clientID=FOO_PRODUCER");
+ ConnectionFactory connectionFactory1Server0 = new
ActiveMQConnectionFactory("tcp://localhost:61616?ha=true&reconnectAttempts=30&clientID=TOO_PRODUCER");
+
+ Connection connectionProducer0 = null;
+ Connection connectionProducer1 = null;
+
+ try {
+ connectionProducer0 = connectionFactory0Server0.createConnection();
+ connectionProducer1 = connectionFactory1Server0.createConnection();
+
+ for (Connection connectionProducer : new Connection[]
{connectionProducer0, connectionProducer1}) {
+ Session session = connectionProducer.createSession(false,
Session.AUTO_ACKNOWLEDGE);
+
+ Queue queue = session.createQueue("exampleQueue" +
connectionProducer.getClientID().substring(0, 3));
+ MessageProducer sender = session.createProducer(queue);
+ for (int i = 0; i < 100; i++) {
+ TextMessage message = session.createTextMessage("Hello world n"
+ i + " - " + connectionProducer.getClientID().substring(0, 3));
+ System.out.println("Sending message " + message.getText() + "/"
+ connectionProducer.getClientID());
+ sender.send(message);
+ }
+ }
+ } finally {
+ if (connectionProducer0 != null) {
+ connectionProducer0.close();
+ }
+
+ if (connectionProducer1 != null) {
+ connectionProducer1.close();
+ }
+ }
+
+ /**
+ * Step 2. create a connection for consumer0 and consumer1, and receive
a few messages.
+ * the server1 will redirect the connection to the same target broker of
the respective producer
+ * from earlier as the new consumer connection uses the same ClientID
prefix.
+ */
+ ConnectionFactory connectionFactory0Server1 = new
ActiveMQConnectionFactory("tcp://localhost:61617?ha=true&reconnectAttempts=30&clientID=TOO_CONSUMER");
+ ConnectionFactory connectionFactory1Server1 = new
ActiveMQConnectionFactory("tcp://localhost:61617?ha=true&reconnectAttempts=30&clientID=FOO_CONSUMER");
Review comment:
updated
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 634621)
Time Spent: 8h 20m (was: 8h 10m)
> Broker Balancers
> ----------------
>
> Key: ARTEMIS-3365
> URL: https://issues.apache.org/jira/browse/ARTEMIS-3365
> Project: ActiveMQ Artemis
> Issue Type: New Feature
> Reporter: Domenico Francesco Bruscino
> Assignee: Domenico Francesco Bruscino
> Priority: Major
> Time Spent: 8h 20m
> Remaining Estimate: 0h
>
> This feature adds the broker balancers to distribute the incoming client
> connections across multiple brokers.
> It provides a native redirection for supported clients and a new management
> API for other clients. The native redirection can be enabled per acceptor and
> is supported only for CORE and AMQP clients.
> See the [draft
> documentation|https://github.com/brusdev/activemq-artemis/blob/broker_balancers/docs/user-manual/en/broker-balancers.md]
> for further details.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)