consuming messages with REST API in Java

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

consuming messages with REST API in Java

Luigi Suardi
hello activemq,

i am using amq 5.15.9 and want to consume messages using the REST API. i
am hitting the issue described in the documentation @
https://activemq.apache.org/rest

"When consuming messages using the REST API, you have to keep session
alive between GET requests, or you’ll create a separate consumer for
every request and due to prefetch limit your succeeding call will hang."

I wrote my consumer in Java 8 using
org.springframework.web.client.RestTemplate

         HttpHeaders headers = new HttpHeaders();
         headers.set("Authorization", getAuthorizationHeader());
         headers.set("Connection", "Keep-Alive");

         HttpEntity<String> request = new HttpEntity<String>("", headers);

         ResponseEntity<String> response =
             restTemplate.exchange(
"http://localhost:8161/api/message/quote?type=queue",
                 HttpMethod.GET,
                 request,
                 String.class);

and getting a successful consume on first request and hanging request
from then on with 204 response after a long wait...

can someone please share an example of working Java consumer using the
REST API? I does not matter if based on RestTemplate or other tool for
HTTP client requests.

Thanks much in advance.
Luigi





Reply | Threaded
Open this post in threaded view
|

Re: consuming messages with REST API in Java

Tim Bain
I'm curious, why would you use the REST API from a Java client rather than
using the Java-native JMS API, which doesn't have edge cases such as the
need to keep the connection alive and the challenges with messages getting
stranded in prefetch buffers?

Tim

On Wed, Jul 10, 2019, 10:27 AM Luigi Suardi <[hidden email]> wrote:

> hello activemq,
>
> i am using amq 5.15.9 and want to consume messages using the REST API. i
> am hitting the issue described in the documentation @
> https://activemq.apache.org/rest
>
> "When consuming messages using the REST API, you have to keep session
> alive between GET requests, or you’ll create a separate consumer for
> every request and due to prefetch limit your succeeding call will hang."
>
> I wrote my consumer in Java 8 using
> org.springframework.web.client.RestTemplate
>
>          HttpHeaders headers = new HttpHeaders();
>          headers.set("Authorization", getAuthorizationHeader());
>          headers.set("Connection", "Keep-Alive");
>
>          HttpEntity<String> request = new HttpEntity<String>("", headers);
>
>          ResponseEntity<String> response =
>              restTemplate.exchange(
> "http://localhost:8161/api/message/quote?type=queue",
>                  HttpMethod.GET,
>                  request,
>                  String.class);
>
> and getting a successful consume on first request and hanging request
> from then on with 204 response after a long wait...
>
> can someone please share an example of working Java consumer using the
> REST API? I does not matter if based on RestTemplate or other tool for
> HTTP client requests.
>
> Thanks much in advance.
> Luigi
>
>
>
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: consuming messages with REST API in Java

Luigi Suardi
AMQ would be one of many microservices in our service oriented (hybrid
cloud) architecture... all communication is REST / HTTP based with API
gateways and other tools used to route, balance and control access to
API end points... I am not sure how to fit JMS in this scenario.

Thoughts?

Luigi



On 7/11/2019 2:41 PM, Tim Bain wrote:

> I'm curious, why would you use the REST API from a Java client rather than
> using the Java-native JMS API, which doesn't have edge cases such as the
> need to keep the connection alive and the challenges with messages getting
> stranded in prefetch buffers?
>
> Tim
>
> On Wed, Jul 10, 2019, 10:27 AM Luigi Suardi <[hidden email]> wrote:
>
>> hello activemq,
>>
>> i am using amq 5.15.9 and want to consume messages using the REST API. i
>> am hitting the issue described in the documentation @
>> https://activemq.apache.org/rest
>>
>> "When consuming messages using the REST API, you have to keep session
>> alive between GET requests, or you’ll create a separate consumer for
>> every request and due to prefetch limit your succeeding call will hang."
>>
>> I wrote my consumer in Java 8 using
>> org.springframework.web.client.RestTemplate
>>
>>           HttpHeaders headers = new HttpHeaders();
>>           headers.set("Authorization", getAuthorizationHeader());
>>           headers.set("Connection", "Keep-Alive");
>>
>>           HttpEntity<String> request = new HttpEntity<String>("", headers);
>>
>>           ResponseEntity<String> response =
>>               restTemplate.exchange(
>> "http://localhost:8161/api/message/quote?type=queue",
>>                   HttpMethod.GET,
>>                   request,
>>                   String.class);
>>
>> and getting a successful consume on first request and hanging request
>> from then on with 204 response after a long wait...
>>
>> can someone please share an example of working Java consumer using the
>> REST API? I does not matter if based on RestTemplate or other tool for
>> HTTP client requests.
>>
>> Thanks much in advance.
>> Luigi
>>
>>
>>
>>
>>
>>