Skip to content

Commit

Permalink
ARTEMIS-4873: tweak example to avoid potential NPE from race between …
Browse files Browse the repository at this point in the history
…creating new backlog and replenishing credit

Also swap startup/shutdown order to reduce reconnect logging
  • Loading branch information
gemmellr authored and tabish121 committed Jul 26, 2024
1 parent c5d2ab6 commit bc86b5d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,8 @@ public static void main(final String[] args) throws Exception {
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");
Expand All @@ -87,6 +83,12 @@ public static void main(final String[] args) throws Exception {
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");
Expand Down

0 comments on commit bc86b5d

Please sign in to comment.