You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by ChicagoBob123 <bo...@bobfx.com> on 2010/09/08 20:32:24 UTC

configuring and using ActiveMQ with http

Anyone use ActiveMQ with http before? 

I got work to buy the book ActiveMQ in Action. 
Its not too bad but its not answering my question directly. Its obvious you
can use http transport but its not clear on how from the client perspective. 

I think you need to alter activemq.xml in the <transportConnectors> section
by adding 
<transportConnector
name="http"
uri="http://localhost:8080?trace=true" />



On the client side using, NMS in my case, you 
 Apache.NMS.ActiveMQ.ConnectionFactory connect = new
Apache.NMS.ActiveMQ.ConnectionFactory("activemq:htp:://172.16.0.51:61616");
this just throws an error. Cant parse URI. ??

Ideas


-- 
View this message in context: http://activemq.2283324.n4.nabble.com/configuring-and-using-ActiveMQ-with-http-tp2531794p2531794.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Problems with configuring and using ActiveMQ with http

Posted by ChicagoBob123 <bo...@bobfx.com>.
Dejan,
and everyone else THANK YOU.

I read this many times but did not understand how to implement it. 
But after going through it again and again and doing some trial 
and error I have finally found a combination that works. Let me share some
C# code.. 
This REST protocol really balances things out. It may not be nearly as fast
as native tcp etc.. but 
it allows for C# programmers without any libraries to get data from an
ActiveMQ queue. 

NOTE: I HAD to use clientID. (Maybe I am doing something wrong)
Without it the http GET would hang even though I thought I was using the
cookie info correctly. 
Post works with a text stream as well. So now I have a simple XML http post
and get.
Thanks everyone.  
Now I have more questions but will ask in another thread. 
Here is some C# code that works here. Thanks.

// gets one message from the queue at a time.
void ReadMessageQueue()
{
 // disable button so it can not be called twice 
 // because if there is no data in queue the timeout takes a while
 GetQueue.Enabled = false;
 byte[] buf = new byte[8192];
 String myuri =
"http://localhost:8080/demo/message/abc?type=queue&clientId=myid";  
 HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(data);
 myHttpWebRequest.Method = "GET"; 
 // Set the content type of the data being posted. 
 myHttpWebRequest.ContentType = "application/x-www-form-urlencoded"; 
 // I created a global defined CookieContainer object that I reuse every
time I 
 // connect 
 myHttpWebRequest.CookieContainer = CC; 
 WebResponse myHttpWebResponse =
(WebResponse)myHttpWebRequest.GetResponse();
 CC = myHttpWebRequest.CookieContainer;
 // get the response stream
 Stream receiveStream = (Stream)myHttpWebResponse.GetResponseStream();
 // Reads up to 8K characters at a time 
 int count = receiveStream.Read(buf, 0, buf.Length); 
 String TotalMessage;
 TotalMessage = "";
 while (count > 0)  
  {
   String str = Encoding.ASCII.GetString(buf, 0, count);
   TotalMessage += str;
   count = receiveStream.Read(buf, 0, buf.Length); 
  }

 // display returned message to top on screen
 MessageRecieved.Text = TotalMessage + "\r\n" + MessageRecieved.Text;
 // Releases the resources of the response.
 receiveStream.Close();
 // Releases the resources of the Stream.
 myHttpWebResponse.Close();

 // enable button 
 GetQueue.Enabled = true;
}

  void PostMessageToQueue()
  {
   String data = "http://localhost:8080/demo/message/abc?type=queue";
   HttpWebRequest myHttpWebRequest =
(HttpWebRequest)WebRequest.Create(data);
   myHttpWebRequest.Method = "POST";

   string postData = "&body=" + MessageToSend.Text;
   ASCIIEncoding encoding = new ASCIIEncoding (); 
   byte[] byte1 = encoding.GetBytes (postData); 

   // Set the content type of the data being posted. 
   myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";   
   // Set the content length of the string being posted. 
   myHttpWebRequest.ContentLength = byte1.Length;
   Stream os = null;
   os = myHttpWebRequest.GetRequestStream();
   os.Write(byte1, 0, byte1.Length);
   os.Close();

   WebResponse myHttpWebResponse =
(WebResponse)myHttpWebRequest.GetResponse();

   Stream receiveStream = (Stream)myHttpWebResponse.GetResponseStream();
   Encoding encode = System.Text.Encoding.GetEncoding("utf-8");

   // Pipes the stream to a higher level stream reader with the required
encoding format. 
   StreamReader readStream = new StreamReader(receiveStream, encode);

   Char[] read = new Char[256];
   // Reads 256 characters at a time.    
   int count = readStream.Read(read, 0, 256);
   List<String> retval = new List<String>();
   while (count > 0)
   {
    // Dumps the 256 characters on a string and displays the string to the
console.
    String str = new String(read, 0, count);
    retval.Add(str);
    count = readStream.Read(read, 0, 256);
   }

   readStream.Close();

   // Releases the resources of the response.
   receiveStream.Close();

   // Releases the resources of the Stream.
   myHttpWebResponse.Close();

  }
-- 
View this message in context: http://activemq.2283324.n4.nabble.com/configuring-and-using-ActiveMQ-with-http-tp2531794p2534590.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Problems with configuring and using ActiveMQ with http

Posted by Dejan Bosanac <de...@nighttale.net>.
Hi Bob,

Take a look at this: http://activemq.apache.org/rest.html#REST-Consuming

the problem is that every GET request you send creates a new consumer.
You need to:

a) keep session between requests, as explained in the article above
b) or, use clientId param in your call, like

 http://localhost:8080/demo/message/abc?type=queue&clientId=test

Cheers
--
Dejan Bosanac - http://twitter.com/dejanb

Open Source Integration - http://fusesource.com/
ActiveMQ in Action - http://www.manning.com/snyder/
Blog - http://www.nighttale.net



On Thu, Sep 9, 2010 at 11:38 PM, ChicagoBob123 <bo...@bobfx.com> wrote:
>
> Last note. I can post to this queue just fine via http. Its just dequeueing
> giving me a problem.
> Any ideas would be great.
>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> OK here is whats happening
> I queue 5 items
>
> I can read the queue twice. via http.
> http://localhost:8080/demo/message/abc?&type=queue
>
> Then I can not read the queue unless I kill and restart ActiveMQ.
> Mystery to me folks the error I get
>
> By checking here I can see an error.
>
> http://localhost:8080/admin/message.jsp?queues=abc
> No connection could be found for ID ID:GOODSERVER-4155-1284058239344-4:12
>
> Ideas? ?
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/configuring-and-using-ActiveMQ-with-http-tp2531794p2533618.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>

Re: Problems with configuring and using ActiveMQ with http

Posted by ChicagoBob123 <bo...@bobfx.com>.
Last note. I can post to this queue just fine via http. Its just dequeueing
giving me a problem. 
Any ideas would be great.  

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
OK here is whats happening 
I queue 5 items 

I can read the queue twice. via http. 
http://localhost:8080/demo/message/abc?&type=queue

Then I can not read the queue unless I kill and restart ActiveMQ. 
Mystery to me folks the error I get 

By checking here I can see an error. 

http://localhost:8080/admin/message.jsp?queues=abc
No connection could be found for ID ID:GOODSERVER-4155-1284058239344-4:12 

Ideas? ? 
-- 
View this message in context: http://activemq.2283324.n4.nabble.com/configuring-and-using-ActiveMQ-with-http-tp2531794p2533618.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Problems with configuring and using ActiveMQ with http

Posted by ChicagoBob123 <bo...@bobfx.com>.
OK here is whats happening 
I queue 5 items 

I can read the queue twice. via http. 
http://localhost:8080/demo/message/abc?&type=queue

Then I can not read the queue unless I kill and restart ActiveMQ. 
Mystery to me folks the error I get

By checking here I can see an error. 

http://localhost:8080/admin/message.jsp?queues=abc
No connection could be found for ID ID:GOODSERVER-4155-1284058239344-4:12 

Ideas? ? 
-- 
View this message in context: http://activemq.2283324.n4.nabble.com/configuring-and-using-ActiveMQ-with-http-tp2531794p2533589.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: configuring and using ActiveMQ with http

Posted by ChicagoBob123 <bo...@bobfx.com>.
I now have 3 questions have reading and trying to make this work. 

First does this actually work reliably? 

Read through some the REST API get from a queue. 
I started by trying to get data from a queue. I have recieved some items
from the queue but its unstable. 
I get no data even when there is data in the queue. Here is the URI I am
sending. 
http://localhost:8080/demo/message/abc?timeout=1000&type=queue 

abc is my queue. I then get this error from

http://localhost:8080/admin/message.jsp?queues=abc
No connection could be found for ID ID:GOODSERVER-4155-1284058239344-4:12 


I altered the port of the jetty webserver to 8080 in the web.xml
Works but I must ask how you protect the admin site? 
Should it not be hidden from port 8080? 
Is there a way to configure it on another port?




-- 
View this message in context: http://activemq.2283324.n4.nabble.com/configuring-and-using-ActiveMQ-with-http-tp2531794p2533561.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: configuring and using ActiveMQ with http

Posted by Dejan Bosanac <de...@nighttale.net>.
Hi Bob,

if you need to send simple text to ActiveMQ using HTTP you can use
REST API: http://activemq.apache.org/rest.html

As for the http transport, it sends messages as XML payloads. The best
source of information is the Java implementation, which you can find
here:

http://svn.apache.org/viewvc/activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/

and especially

http://svn.apache.org/viewvc/activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/xstream/XStreamWireFormat.java?view=markup

which uses XStream to marshall/unmarshall messages


Cheers
--
Dejan Bosanac - http://twitter.com/dejanb

Open Source Integration - http://fusesource.com/
ActiveMQ in Action - http://www.manning.com/snyder/
Blog - http://www.nighttale.net



On Wed, Sep 8, 2010 at 10:33 PM, ChicagoBob123 <bo...@bobfx.com> wrote:
>
> On Wed, 2010-09-08 at 12:41 -0700, ChicagoBob123 wrote:
>> Does the CMS C++ client support Http transport?
> No, only the Java client provides HTTP transport at this time.
> Regards
> --
> Tim Bish
>
> More questions poped up. Where can I find the spec or outline to do
> something like this?
> My guess is I need to write a TCP/IP Socket handler to do a http post and
> one to do a http get.
> Fine but post to what page/URL what and get what page/URL?
>
> Is there a ActiveMQ/Http doc some place for doing this?
> I am guessing to add to queue you would create a http post with text and
> send it.  Is it that simple or is there more?
> Thanks a bunch,
> Bob
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/configuring-and-using-ActiveMQ-with-http-tp2531794p2531988.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>

Re: configuring and using ActiveMQ with http

Posted by ChicagoBob123 <bo...@bobfx.com>.
On Wed, 2010-09-08 at 12:41 -0700, ChicagoBob123 wrote: 
> Does the CMS C++ client support Http transport? 
No, only the Java client provides HTTP transport at this time. 
Regards 
-- 
Tim Bish 

More questions poped up. Where can I find the spec or outline to do
something like this? 
My guess is I need to write a TCP/IP Socket handler to do a http post and
one to do a http get.  
Fine but post to what page/URL what and get what page/URL?  

Is there a ActiveMQ/Http doc some place for doing this? 
I am guessing to add to queue you would create a http post with text and
send it.  Is it that simple or is there more? 
Thanks a bunch,
Bob
-- 
View this message in context: http://activemq.2283324.n4.nabble.com/configuring-and-using-ActiveMQ-with-http-tp2531794p2531988.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: configuring and using ActiveMQ with http

Posted by ChicagoBob123 <bo...@bobfx.com>.
ARGGH BUMMER !!!! Oh well. 
Guess I have to find the source for this and do a little translating if I
can. 
Thanks a bunch. 
-- 
View this message in context: http://activemq.2283324.n4.nabble.com/configuring-and-using-ActiveMQ-with-http-tp2531794p2531955.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: configuring and using ActiveMQ with http

Posted by Timothy Bish <ta...@gmail.com>.
On Wed, 2010-09-08 at 12:41 -0700, ChicagoBob123 wrote:
> Does the CMS C++ client support Http transport?

No, only the Java client provides HTTP transport at this time.

Regards

-- 
Tim Bish

Open Source Integration: http://fusesource.com
ActiveMQ in Action: http://www.manning.com/snyder/

Follow me on Twitter: http://twitter.com/tabish121
My Blog: http://timbish.blogspot.com/


Re: configuring and using ActiveMQ with http

Posted by ChicagoBob123 <bo...@bobfx.com>.
Does the CMS C++ client support Http transport?
-- 
View this message in context: http://activemq.2283324.n4.nabble.com/configuring-and-using-ActiveMQ-with-http-tp2531794p2531912.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: configuring and using ActiveMQ with http

Posted by Timothy Bish <ta...@gmail.com>.
On Wed, 2010-09-08 at 11:32 -0700, ChicagoBob123 wrote:
> Anyone use ActiveMQ with http before? 
> 
> I got work to buy the book ActiveMQ in Action. 
> Its not too bad but its not answering my question directly. Its obvious you
> can use http transport but its not clear on how from the client perspective. 
> 
> I think you need to alter activemq.xml in the <transportConnectors> section
> by adding 
> <transportConnector
> name="http"
> uri="http://localhost:8080?trace=true" />
> 
> 
> 
> On the client side using, NMS in my case, you 
>  Apache.NMS.ActiveMQ.ConnectionFactory connect = new
> Apache.NMS.ActiveMQ.ConnectionFactory("activemq:htp:://172.16.0.51:61616");
> this just throws an error. Cant parse URI. ??
> 
> Ideas
> 
> 

NMS.ActiveMQ doesn't support an HTTP transport so that's why you are
getting this error.  Right now the AMQ NMS client library only supports
tcp and ssl based transports plus a discovery transport for finding
remote brokers.

Regards

-- 
Tim Bish

Open Source Integration: http://fusesource.com
ActiveMQ in Action: http://www.manning.com/snyder/

Follow me on Twitter: http://twitter.com/tabish121
My Blog: http://timbish.blogspot.com/


Re: configuring and using ActiveMQ with http

Posted by "Satterly Nicholas (Nokia-MS/Southwood)" <ni...@nokia.com>.
Try changing the uri to "http://0.0.0.0:8080?trace=true". If you use 
localhost I think it only listens on the loopback address 127.0.0.1.

--Nick.

On 08/09/10 19:32, ext ChicagoBob123 wrote:
>
> Anyone use ActiveMQ with http before?
>
> I got work to buy the book ActiveMQ in Action.
> Its not too bad but its not answering my question directly. Its obvious you
> can use http transport but its not clear on how from the client perspective.
>
> I think you need to alter activemq.xml in the<transportConnectors>  section
> by adding
> <transportConnector
> name="http"
> uri="http://localhost:8080?trace=true" />
>
>
>
> On the client side using, NMS in my case, you
>   Apache.NMS.ActiveMQ.ConnectionFactory connect = new
> Apache.NMS.ActiveMQ.ConnectionFactory("activemq:htp:://172.16.0.51:61616");
> this just throws an error. Cant parse URI. ??
>
> Ideas
>
>