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/09 23:09:12 UTC
Problems with configuring and using ActiveMQ with http
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: 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.