You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by kovacro <ro...@loto-quebec.com> on 2017/05/08 20:37:07 UTC

ActiveMQ REST Api with HTTP

Hello,

I am using:
curl-7.48.0-win32-mingw
apache-activemq-5.14.5-bin (locally)

I can add messages like this:
curl -u admin:admin -d "hello world 1" -H "Content-Type: text/plain" -XPOST
"http://localhost:8161/api/message?destination=queue://Test_Kovac&&clientId=KovacIP1"

curl -u admin:admin -d "hello world 1" -H "Content-Type: text/plain" -XPOST
"http://localhost:8161/api/message?destination=queue://Test_Kovac&&clientId=KovacIP2"

I can retrieve both messages with:
curl -u admin:admin -X GET
"http://localhost:8161/api/message?destination=queue://Test_Kovac?type=queue&clientId=KovacIP1"

1- How come my clientid parameter doesn't filter wich messages I retrieve?
"When using this approach, you don't need to keep sessions alive between
requests, you just need to use the same clientId every time."

---------------------------------------------

Afterwards, I try using selectors, but they don't seem to work either

I insert this:
curl -u admin:admin -d "hello world 1" -H "Content-Type: text/plain" -XPOST
"http://localhost:8161/api/message?destination=queue://Test_Kovac&&clientId=KovacIP1"

curl -u admin:admin -d "test selector" -H "Content-Type: text/plain" -XPOST
"http://localhost:8161/api/message?destination=queue://Test_Kovac&&clientId=KovacIP2&test=2"

curl -u admin:admin -d "hello world 3" -H "Content-Type: text/plain" -XPOST
"http://localhost:8161/api/message?destination=queue://Test_Kovac&&clientId=KovacIP3"

When I try to retrieve test=2 with this command

curl -u admin:admin -H "selector: test=2" -X GET
"http://localhost:8161/api/message?destination=queue://Test_Kovac?type=queue&clientId=KovacIP2"

I have access to all the message. I retreive them all (all 3 of them) 1 by
1.

Why is that?

How does the selector work?

Thanks for your help







--
View this message in context: http://activemq.2283324.n4.nabble.com/ActiveMQ-REST-Api-with-HTTP-tp4725797.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: ActiveMQ REST Api with HTTP

Posted by kovacro <ro...@loto-quebec.com>.
Hello,

Excellent advice:
You should be able to publish your messages and then look at them in the 
web console to confirm that the right values are getting set. 


I see all my messages in the wed admin console.

I see the property test=2 associated with the message.

<http://activemq.2283324.n4.nabble.com/file/n4726036/image1.png> 



--
View this message in context: http://activemq.2283324.n4.nabble.com/ActiveMQ-REST-Api-with-HTTP-tp4725797p4726036.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: ActiveMQ REST Api with HTTP

Posted by Tim Bain <tb...@alumni.duke.edu>.
Is what you're doing (setting them via request parameters on the URL) the
right way to set message header properties (e.g. test=2)? The page doesn't
say explicitly, but I had assumed that you'd need to use the --header
approach.

You should be able to publish your messages and then look at them in the
web console to confirm that the right values are getting set. Once you get
the publisher working right, then you can move on to the consumer,
selectors, etc.

Tim

On May 10, 2017 6:31 AM, "kovacro" <ro...@loto-quebec.com> wrote:

> Hello,
>
> Point 1:
>
> I insert the the 4 following messages
>
> curl -u admin:admin -d "hello world 1" -H "Content-Type: text/plain" -XPOST
> "http://localhost:8161/api/message?destination=queue://
> Test_Kovac&&clientId=KovacIP1"
>
> curl -u admin:admin -d "test selector" -H "selector test" -H "Content-Type:
> text/plain" -XPOST "http://localhost:8161/api/message?
> destination=queue://Test_Kovac&&clientId=KovacIP2&test=2"
>
> curl -u admin:admin -d "hello world 3" -H "Content-Type: text/plain" -XPOST
> "http://localhost:8161/api/message?destination=queue://
> Test_Kovac&&clientId=KovacIP3"
>
> curl -u admin:admin -d "hello world 5" -H "Content-Type: text/plain" -XPOST
> "http://localhost:8161/api/message?destination=queue://
> Test_Kovac&&clientId=KovacIP4"
>
> I retrieve 2 of them with this command
>
> curl -u admin:admin -X GET
> "http://localhost:8161/api/message?destination=queue://
> Test_Kovac?type=queue&clientId=jojo"
>
> When I try with a different clientID, it doesn't work:
>
> curl -u admin:admin -X GET
> "http://localhost:8161/api/message?destination=queue://
> Test_Kovac?type=queue&clientId=KovacIP2"
>
> Since the clientID is not a filter, why doesn't it work?
>
>
> ---------------
> Point 2:
>
> With the 2 followoing messages:
> curl -u admin:admin -d "hello world 1" -H "Content-Type: text/plain" -XPOST
> "http://localhost:8161/api/message?destination=queue://
> Test_Kovac&&clientId=KovacIP1"
>
> curl -u admin:admin -d "test selector=2" -H "selector: test" -H
> "Content-Type: text/plain" -XPOST
> "http://localhost:8161/api/message?destination=queue://
> Test_Kovac&&clientId=KovacIP2&test=2"
>
> I try this selector and it doesn't work, I can retrieve everything:
> curl -u admin:admin -H "selector: test=2" -X GET
> "http://localhost:8161/api/message?destination=queue://
> Test_Kovac?type=queue&clientId=KovacIP2"
>
> Conclusion: I can seem to filter any messages.
>
>
>
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.
> nabble.com/ActiveMQ-REST-Api-with-HTTP-tp4725797p4725883.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>

Re: ActiveMQ REST Api with HTTP

Posted by kovacro <ro...@loto-quebec.com>.
Hello,

Point 1:

I insert the the 4 following messages

curl -u admin:admin -d "hello world 1" -H "Content-Type: text/plain" -XPOST
"http://localhost:8161/api/message?destination=queue://Test_Kovac&&clientId=KovacIP1"

curl -u admin:admin -d "test selector" -H "selector test" -H "Content-Type:
text/plain" -XPOST "http://localhost:8161/api/message?
destination=queue://Test_Kovac&&clientId=KovacIP2&test=2"

curl -u admin:admin -d "hello world 3" -H "Content-Type: text/plain" -XPOST
"http://localhost:8161/api/message?destination=queue://Test_Kovac&&clientId=KovacIP3"

curl -u admin:admin -d "hello world 5" -H "Content-Type: text/plain" -XPOST
"http://localhost:8161/api/message?destination=queue://Test_Kovac&&clientId=KovacIP4"

I retrieve 2 of them with this command

curl -u admin:admin -X GET
"http://localhost:8161/api/message?destination=queue://Test_Kovac?type=queue&clientId=jojo"

When I try with a different clientID, it doesn't work:

curl -u admin:admin -X GET
"http://localhost:8161/api/message?destination=queue://Test_Kovac?type=queue&clientId=KovacIP2"

Since the clientID is not a filter, why doesn't it work?


---------------
Point 2:

With the 2 followoing messages:
curl -u admin:admin -d "hello world 1" -H "Content-Type: text/plain" -XPOST
"http://localhost:8161/api/message?destination=queue://Test_Kovac&&clientId=KovacIP1"

curl -u admin:admin -d "test selector=2" -H "selector: test" -H
"Content-Type: text/plain" -XPOST
"http://localhost:8161/api/message?destination=queue://Test_Kovac&&clientId=KovacIP2&test=2"

I try this selector and it doesn't work, I can retrieve everything:
curl -u admin:admin -H "selector: test=2" -X GET
"http://localhost:8161/api/message?destination=queue://Test_Kovac?type=queue&clientId=KovacIP2"

Conclusion: I can seem to filter any messages.






--
View this message in context: http://activemq.2283324.n4.nabble.com/ActiveMQ-REST-Api-with-HTTP-tp4725797p4725883.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: ActiveMQ REST Api with HTTP

Posted by kovacro <ro...@loto-quebec.com>.
Hello Tim,

First of all, thank you very much for replying.

Concerning point 1:

I have read your answer and I believe you are right. The clientID is not a
filter. 
My Question: What is the function of the clientID, since I can asssign any
value to it and it will work?
Bottom line, I don't understand the meaning of this phrase:
"When using this approach, you don't need to keep sessions alive between
requests, you just need to use the same clientId every time." --> why use
the same clientID?

Concerning point 2:
You write: I don't see anywhere that you're setting the "test" 
header property to "2" when you publish.

On the following page: http://activemq.apache.org/rest.html, they don't seem
to indicate that you must define the selector in the post command (or
sender).
My mistake, I will try it out.
If you can, I would greatly appreciate an example.

Thank you







--
View this message in context: http://activemq.2283324.n4.nabble.com/ActiveMQ-REST-Api-with-HTTP-tp4725797p4725881.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: ActiveMQ REST Api with HTTP

Posted by Tim Bain <tb...@alumni.duke.edu>.
As I understand it, the clientId parameter isn't a selector; rather, it
ensures that your consumer gets messages consistent with what has already
been delivered to it even if the session has expired, but it is not meant
to specify that you only consume messages produced by yourself. So the
delivery of all messages to your consumer in the first example sounds
entirely expected.

In your second example, I don't see anywhere that you're setting the "test"
header property to "2" when you publish, so I'd expect that none of them
would be returned to your client. You could try attaching a JMX viewer such
as JConsole to the broker immediately after your consumer connects, and
navigating the MBeans to find the consumer to check whether the broker
believes the test=2 selector is in effect.  Maybe something's going wrong
and the selector's not making it all the way to the broker...

Tim

On Mon, May 8, 2017 at 2:37 PM, kovacro <ro...@loto-quebec.com>
wrote:

> Hello,
>
> I am using:
> curl-7.48.0-win32-mingw
> apache-activemq-5.14.5-bin (locally)
>
> I can add messages like this:
> curl -u admin:admin -d "hello world 1" -H "Content-Type: text/plain" -XPOST
> "http://localhost:8161/api/message?destination=queue://
> Test_Kovac&&clientId=KovacIP1"
>
> curl -u admin:admin -d "hello world 1" -H "Content-Type: text/plain" -XPOST
> "http://localhost:8161/api/message?destination=queue://
> Test_Kovac&&clientId=KovacIP2"
>
> I can retrieve both messages with:
> curl -u admin:admin -X GET
> "http://localhost:8161/api/message?destination=queue://
> Test_Kovac?type=queue&clientId=KovacIP1"
>
> 1- How come my clientid parameter doesn't filter wich messages I retrieve?
> "When using this approach, you don't need to keep sessions alive between
> requests, you just need to use the same clientId every time."
>
> ---------------------------------------------
>
> Afterwards, I try using selectors, but they don't seem to work either
>
> I insert this:
> curl -u admin:admin -d "hello world 1" -H "Content-Type: text/plain" -XPOST
> "http://localhost:8161/api/message?destination=queue://
> Test_Kovac&&clientId=KovacIP1"
>
> curl -u admin:admin -d "test selector" -H "Content-Type: text/plain" -XPOST
> "http://localhost:8161/api/message?destination=queue://
> Test_Kovac&&clientId=KovacIP2&test=2"
>
> curl -u admin:admin -d "hello world 3" -H "Content-Type: text/plain" -XPOST
> "http://localhost:8161/api/message?destination=queue://
> Test_Kovac&&clientId=KovacIP3"
>
> When I try to retrieve test=2 with this command
>
> curl -u admin:admin -H "selector: test=2" -X GET
> "http://localhost:8161/api/message?destination=queue://
> Test_Kovac?type=queue&clientId=KovacIP2"
>
> I have access to all the message. I retreive them all (all 3 of them) 1 by
> 1.
>
> Why is that?
>
> How does the selector work?
>
> Thanks for your help
>
>
>
>
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.
> nabble.com/ActiveMQ-REST-Api-with-HTTP-tp4725797.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>