This is an automated email from the ASF dual-hosted git repository.

tabish pushed a commit to branch development
in repository https://gitbox.apache.org/repos/asf/activemq-artemis-examples.git


The following commit(s) were added to refs/heads/development by this push:
     new bc86b5d  ARTEMIS-4873: tweak example to avoid potential NPE from race 
between creating new backlog and replenishing credit
bc86b5d is described below

commit bc86b5d7a1b6c8fe063d1ce6c877d7c962e26cd0
Author: Robbie Gemmell <[email protected]>
AuthorDate: Fri Jul 26 16:37:32 2024 +0100

    ARTEMIS-4873: tweak example to avoid potential NPE from race between 
creating new backlog and replenishing credit
    
    Also swap startup/shutdown order to reduce reconnect logging
---
 .../amqp-federation-queue-pull-messages/pom.xml    | 26 +++++++++++-----------
 .../jms/example/BrokerFederationExample.java       | 14 +++++++-----
 2 files changed, 21 insertions(+), 19 deletions(-)

diff --git 
a/examples/features/broker-connection/amqp-federation-queue-pull-messages/pom.xml
 
b/examples/features/broker-connection/amqp-federation-queue-pull-messages/pom.xml
index f70a367..b6efe24 100644
--- 
a/examples/features/broker-connection/amqp-federation-queue-pull-messages/pom.xml
+++ 
b/examples/features/broker-connection/amqp-federation-queue-pull-messages/pom.xml
@@ -76,37 +76,37 @@ under the License.
                      <javaOptions>-Djava.net.preferIPv4Stack=true</javaOptions>
                   </configuration>
                </execution>
-               <!-- we first start broker 1, to avoid reconnecting statements 
-->
+               <!-- we first start broker 2, to avoid reconnecting statements 
-->
                <execution>
-                  <id>start1</id>
+                  <id>start2</id>
                   <goals>
                      <goal>cli</goal>
                   </goals>
                   <configuration>
                      <ignore>${noServer}</ignore>
                      <spawn>true</spawn>
-                     <location>${basedir}/target/server1</location>
-                     <testURI>tcp://localhost:5660</testURI>
+                     <location>${basedir}/target/server2</location>
+                     <testURI>tcp://localhost:5770</testURI>
                      <args>
                         <param>run</param>
                      </args>
-                     <name>server1</name>
+                     <name>server2</name>
                   </configuration>
                </execution>
                <execution>
-                  <id>start2</id>
+                  <id>start1</id>
                   <goals>
                      <goal>cli</goal>
                   </goals>
                   <configuration>
                      <spawn>true</spawn>
                      <ignore>${noServer}</ignore>
-                     <location>${basedir}/target/server2</location>
-                     <testURI>tcp://localhost:5770</testURI>
+                     <location>${basedir}/target/server1</location>
+                     <testURI>tcp://localhost:5660</testURI>
                      <args>
                         <param>run</param>
                      </args>
-                     <name>server2</name>
+                     <name>server1</name>
                   </configuration>
                </execution>
                <execution>
@@ -121,23 +121,23 @@ under the License.
                   </configuration>
                </execution>
                <execution>
-                  <id>stop2</id>
+                  <id>stop1</id>
                   <goals>
                      <goal>stop</goal>
                   </goals>
                   <configuration>
                      <ignore>${noServer}</ignore>
-                     <location>${basedir}/target/server2</location>
+                     <location>${basedir}/target/server1</location>
                   </configuration>
                </execution>
                <execution>
-                  <id>stop1</id>
+                  <id>stop2</id>
                   <goals>
                      <goal>stop</goal>
                   </goals>
                   <configuration>
                      <ignore>${noServer}</ignore>
-                     <location>${basedir}/target/server1</location>
+                     <location>${basedir}/target/server2</location>
                   </configuration>
                </execution>
             </executions>
diff --git 
a/examples/features/broker-connection/amqp-federation-queue-pull-messages/src/main/java/org/apache/activemq/artemis/jms/example/BrokerFederationExample.java
 
b/examples/features/broker-connection/amqp-federation-queue-pull-messages/src/main/java/org/apache/activemq/artemis/jms/example/BrokerFederationExample.java
index 823bd6f..1654cb6 100644
--- 
a/examples/features/broker-connection/amqp-federation-queue-pull-messages/src/main/java/org/apache/activemq/artemis/jms/example/BrokerFederationExample.java
+++ 
b/examples/features/broker-connection/amqp-federation-queue-pull-messages/src/main/java/org/apache/activemq/artemis/jms/example/BrokerFederationExample.java
@@ -72,12 +72,8 @@ public class BrokerFederationExample {
       System.out.println("Consumer on server 2 received message: " + 
receivedFromC2.getText());
       System.out.println("Consumer on server 2 received message: " + 
receivedFromC3.getText());
 
-      final TextMessage receivedFromC1 = (TextMessage) 
consumerOn1.receive(10_000);
-
-      System.out.println("Consumer on server 1 received message: " + 
receivedFromC1.getText());
-
-      // Now create local backlog on server 1 which should prevent any 
messages being federated
-      // from server 2 and the local consumer on server 2 should be able to 
receive them
+      // Now create more local backlog on server 1 which should prevent more 
messages being federated
+      // from server 2 and the local consumer on server 2 should be able to 
receive them all
 
       final TextMessage messageSent4 = 
sessionOnServer1.createTextMessage("message #4");
       final TextMessage messageSent5 = 
sessionOnServer1.createTextMessage("message #5");
@@ -87,6 +83,12 @@ public class BrokerFederationExample {
       producerOn1.send(messageSent5);
       producerOn1.send(messageSent6);
 
+      // Consume the first message from server1 (federated from server2 on 
first send)
+
+      final TextMessage receivedFromC1 = (TextMessage) 
consumerOn1.receive(10_000);
+
+      System.out.println("Consumer on server 1 received message: " + 
receivedFromC1.getText());
+
       // These should stay local to server 2 and be consumed when pulled by 
the consumer on 2
 
       final TextMessage messageSent7 = 
sessionOnServer2.createTextMessage("message #7");


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to