[jira] [Work logged] (ARTEMIS-4234) EmbeddedActiveMQResource is able to receive only first message

2023-04-10 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/ARTEMIS-4234?focusedWorklogId=855910=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-855910
 ]

ASF GitHub Bot logged work on ARTEMIS-4234:
---

Author: ASF GitHub Bot
Created on: 10/Apr/23 16:20
Start Date: 10/Apr/23 16:20
Worklog Time Spent: 10m 
  Work Description: gemmellr merged PR #4429:
URL: https://github.com/apache/activemq-artemis/pull/4429




Issue Time Tracking
---

Worklog Id: (was: 855910)
Time Spent: 0.5h  (was: 20m)

> EmbeddedActiveMQResource is able to receive only first message
> --
>
> Key: ARTEMIS-4234
> URL: https://issues.apache.org/jira/browse/ARTEMIS-4234
> Project: ActiveMQ Artemis
>  Issue Type: Bug
>  Components: Broker
>Affects Versions: 2.28.0
>Reporter: Dominik Kawczyński
>Assignee: Timothy A. Bish
>Priority: Major
> Fix For: 2.29.0
>
>  Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> Hi,
> i have encountered a problem with embedded Artemis.
> Using *EmbeddedActiveMQResource* _receiveMessage_ method im able to receive 
> only one message from queue.
> Please look at following code:
> {code:java}
> artemis.start()
> def firstMessage = 'test message 1'
> sendMessage(firstMessage, 'test_queue')
> def firstReceivedMessage = artemis.receiveMessage('test_queue', 1000)
> println(' FIRST MESSAGE:')
> println('' + firstReceivedMessage.stringBody)
> /*
> will work if artemis is restarted during test
> artemis.stop()
> artemis.start()
> */
> def secondMessage = 'test message 2'
> sendMessage(secondMessage, 'test_queue')
> def secondReceivedMessage = artemis.receiveMessage('test_queue', 1000)
> println(' SECOND MESSAGE:')
> println('' + secondReceivedMessage.stringBody)
> then:
> firstMessage == firstReceivedMessage.stringBody
> secondMessage == secondReceivedMessage.stringBody {code}
> I'm getting null as secondReceivedMessage, and NPE in effect later.
>  
> The reason is (i assume) that first invocation  is creating a consumer, that 
> is getting second message, before i invoke receiveMessage method second time 
> (i see in logs that second message was consumed)
>  
> Is this expected behavior?
> receiveMessage is returning only one message, so my assumption was, that i 
> can invoke it several times to retrieve consequential messages, and i have 
> not found any documentation explaining current behavior.
>  
> I have created repo with reproducible example:
> [https://github.com/dmkaw/embedded-artemis-issue]
>  
> Thanks in advance.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Work logged] (ARTEMIS-4234) EmbeddedActiveMQResource is able to receive only first message

2023-04-10 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/ARTEMIS-4234?focusedWorklogId=855779=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-855779
 ]

ASF GitHub Bot logged work on ARTEMIS-4234:
---

Author: ASF GitHub Bot
Created on: 10/Apr/23 11:45
Start Date: 10/Apr/23 11:45
Worklog Time Spent: 10m 
  Work Description: gemmellr commented on code in PR #4429:
URL: https://github.com/apache/activemq-artemis/pull/4429#discussion_r1161654982


##
artemis-junit/artemis-junit-commons/src/main/java/org/apache/activemq/artemis/junit/EmbeddedActiveMQDelegate.java:
##
@@ -626,43 +625,51 @@ public void sendMessage(SimpleString address, 
ClientMessage message) {
   public ClientMessage receiveMessage(SimpleString address, long timeout, 
boolean browseOnly) {
  checkSession();
 
- ClientConsumer consumer = null;
- try {
-consumer = session.createConsumer(address, browseOnly);
- } catch (ActiveMQException amqEx) {
-throw new EmbeddedActiveMQResourceException(String.format("Failed 
to create consumer for %s",
-  
address.toString()),
-amqEx);
- }
-
- ClientMessage message = null;
- if (timeout > 0) {
-try {
-   message = consumer.receive(timeout);
-} catch (ActiveMQException amqEx) {
-   throw new 
EmbeddedActiveMQResourceException(String.format("ClientConsumer.receive( 
timeout = %d ) for %s failed",
- 
timeout, address.toString()),
-   amqEx);
+ EmbeddedActiveMQResourceException failureCause = null;
+
+ try (ClientConsumer consumer = session.createConsumer(address, 
browseOnly)) {
+ClientMessage message = null;
+if (timeout > 0) {
+   try {
+  message = consumer.receive(timeout);
+   } catch (ActiveMQException amqEx) {
+  failureCause =  new 
EmbeddedActiveMQResourceException(String.format("ClientConsumer.receive( 
timeout = %d ) for %s failed",
+
timeout, address.toString()), amqEx);
+   }
+} else if (timeout == 0) {
+   try {
+  message = consumer.receiveImmediate();
+   } catch (ActiveMQException amqEx) {
+  failureCause = new 
EmbeddedActiveMQResourceException(String.format("ClientConsumer.receiveImmediate()
 for %s failed",
+   
address.toString()), amqEx);
+   }
+} else {
+   try {
+  message = consumer.receive();
+   } catch (ActiveMQException amqEx) {
+  failureCause = new 
EmbeddedActiveMQResourceException(String.format("ClientConsumer.receive() for 
%s failed",
+   
address.toString()), amqEx);
+   }
 }
- } else if (timeout == 0) {
-try {
-   message = consumer.receiveImmediate();
-} catch (ActiveMQException amqEx) {
-   throw new 
EmbeddedActiveMQResourceException(String.format("ClientConsumer.receiveImmediate()
 for %s failed",
- 
address.toString()),
-   amqEx);
+
+if (message != null) {
+   try {
+  message.acknowledge();
+   } catch (ActiveMQException amqEx) {
+  failureCause = new 
EmbeddedActiveMQResourceException(String.format("ClientMessage.acknowledge() 
for %s from %s failed",
+   
message, address.toString()), amqEx);
+   }
 }
- } else {
-try {
-   message = consumer.receive();
-} catch (ActiveMQException amqEx) {
-   throw new 
EmbeddedActiveMQResourceException(String.format("ClientConsumer.receive() for 
%s failed",
- 
address.toString()),
-   amqEx);
+
+return message;
+ } catch (ActiveMQException amqEx) {

Review Comment:
   It only seems to look at and throws 'failureCause' if it catches 
ActiveMQException in the outer catch wrapper. All the inner catch wrappers 
swallow ActiveMQException while setting failureCause, meaning that failureCause 
then wont be looked at since if 

[jira] [Work logged] (ARTEMIS-4234) EmbeddedActiveMQResource is able to receive only first message

2023-04-07 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/ARTEMIS-4234?focusedWorklogId=855537=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-855537
 ]

ASF GitHub Bot logged work on ARTEMIS-4234:
---

Author: ASF GitHub Bot
Created on: 07/Apr/23 15:54
Start Date: 07/Apr/23 15:54
Worklog Time Spent: 10m 
  Work Description: tabish121 opened a new pull request, #4429:
URL: https://github.com/apache/activemq-artemis/pull/4429

   The JUnit resource has a couple bugs in both the send and receive path that 
result in only one message being received if the receive method is called 
repeatedly and some send drop the provided properties. Cleaned up some tests to 
the point of showing the errors and ensuring that at least basic functionality 
is tested.




Issue Time Tracking
---

Worklog Id: (was: 855537)
Remaining Estimate: 0h
Time Spent: 10m

> EmbeddedActiveMQResource is able to receive only first message
> --
>
> Key: ARTEMIS-4234
> URL: https://issues.apache.org/jira/browse/ARTEMIS-4234
> Project: ActiveMQ Artemis
>  Issue Type: Bug
>  Components: Broker
>Affects Versions: 2.28.0
>Reporter: Dominik Kawczyński
>Assignee: Timothy A. Bish
>Priority: Major
> Fix For: 2.29.0
>
>  Time Spent: 10m
>  Remaining Estimate: 0h
>
> Hi,
> i have encountered a problem with embedded Artemis.
> Using *EmbeddedActiveMQResource* _receiveMessage_ method im able to receive 
> only one message from queue.
> Please look at following code:
> {code:java}
> artemis.start()
> def firstMessage = 'test message 1'
> sendMessage(firstMessage, 'test_queue')
> def firstReceivedMessage = artemis.receiveMessage('test_queue', 1000)
> println(' FIRST MESSAGE:')
> println('' + firstReceivedMessage.stringBody)
> /*
> will work if artemis is restarted during test
> artemis.stop()
> artemis.start()
> */
> def secondMessage = 'test message 2'
> sendMessage(secondMessage, 'test_queue')
> def secondReceivedMessage = artemis.receiveMessage('test_queue', 1000)
> println(' SECOND MESSAGE:')
> println('' + secondReceivedMessage.stringBody)
> then:
> firstMessage == firstReceivedMessage.stringBody
> secondMessage == secondReceivedMessage.stringBody {code}
> I'm getting null as secondReceivedMessage, and NPE in effect later.
>  
> The reason is (i assume) that first invocation  is creating a consumer, that 
> is getting second message, before i invoke receiveMessage method second time 
> (i see in logs that second message was consumed)
>  
> Is this expected behavior?
> receiveMessage is returning only one message, so my assumption was, that i 
> can invoke it several times to retrieve consequential messages, and i have 
> not found any documentation explaining current behavior.
>  
> I have created repo with reproducible example:
> [https://github.com/dmkaw/embedded-artemis-issue]
>  
> Thanks in advance.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)