mirror of https://github.com/apache/activemq.git
changed parameter handling to impose a strict ordering to avoid reordering of messages by client libraries
git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@415827 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
26c45dee0a
commit
6fbb56868f
|
@ -90,7 +90,16 @@ public class MessageListenerServlet extends MessageServletSupport {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a message to a destination
|
* Sends a message to a destination or manage subscriptions.
|
||||||
|
*
|
||||||
|
* If the the content type of the POST is <code>application/x-www-form-urlencoded</code>, then the form parameters
|
||||||
|
* "destination", "message" and "type" are used to pass a message or a subscription. If multiple messages
|
||||||
|
* or subscriptions are passed in a single post, then additional parameters are shortened to "dN", "mN" and "tN"
|
||||||
|
* where N is an index starting from 1. The type is either "send", "listen" or "unlisten". For send types,
|
||||||
|
* the message is the text of the TextMessage, otherwise it is the ID to be used for the subscription.
|
||||||
|
*
|
||||||
|
* If the content type is not <code>application/x-www-form-urlencoded</code>, then the body of the post is
|
||||||
|
* sent as the message to a destination that is derived from a query parameter, the URL or the default destination.
|
||||||
*
|
*
|
||||||
* @param request
|
* @param request
|
||||||
* @param response
|
* @param response
|
||||||
|
@ -110,30 +119,30 @@ public class MessageListenerServlet extends MessageServletSupport {
|
||||||
log.debug("POST client="+client+" session="+request.getSession().getId()+" info="+request.getPathInfo()+" contentType="+request.getContentType());
|
log.debug("POST client="+client+" session="+request.getSession().getId()+" info="+request.getPathInfo()+" contentType="+request.getContentType());
|
||||||
// dump(request.getParameterMap());
|
// dump(request.getParameterMap());
|
||||||
}
|
}
|
||||||
String[] destinations = request.getParameterValues("destination");
|
|
||||||
String[] messages = request.getParameterValues("message");
|
|
||||||
String[] types = request.getParameterValues("type");
|
|
||||||
|
|
||||||
if (destinations.length!=messages.length || messages.length!=types.length)
|
int messages=0;
|
||||||
{
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("ERROR destination="+destinations.length+" message="+messages.length+" type="+types.length);
|
|
||||||
}
|
|
||||||
response.sendError(HttpServletResponse.SC_BAD_REQUEST,"missmatched destination, message or type");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i=0;i<types.length;i++)
|
// loop until no more messages
|
||||||
|
while (true)
|
||||||
{
|
{
|
||||||
|
// Get the message parameters. Multiple messages are encoded with more compact parameter names.
|
||||||
|
String destination_name = request.getParameter(messages==0?"destination":("d"+messages));
|
||||||
|
String message = request.getParameter(messages==0?"message":("m"+messages));
|
||||||
|
String type = request.getParameter(messages==0?"type":("t"+messages));
|
||||||
|
|
||||||
|
if (destination_name==null || message==null || type==null)
|
||||||
|
break;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String type=types[i];
|
Destination destination=getDestination(client,request,destination_name);
|
||||||
Destination destination=getDestination(client,request,destinations[i]);
|
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug(i+" destination="+destinations[i]+" message="+messages[i]+" type="+types[i]);
|
log.debug(messages+" destination="+destination_name+" message="+message+" type="+type);
|
||||||
log.debug(destination+" is a "+destination.getClass().getName());
|
log.debug(destination+" is a "+destination.getClass().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
messages++;
|
||||||
|
|
||||||
if ("listen".equals(type))
|
if ("listen".equals(type))
|
||||||
{
|
{
|
||||||
Listener listener = getListener(request);
|
Listener listener = getListener(request);
|
||||||
|
@ -142,9 +151,9 @@ public class MessageListenerServlet extends MessageServletSupport {
|
||||||
MessageAvailableConsumer consumer = (MessageAvailableConsumer) client.getConsumer(destination);
|
MessageAvailableConsumer consumer = (MessageAvailableConsumer) client.getConsumer(destination);
|
||||||
|
|
||||||
consumer.setAvailableListener(listener);
|
consumer.setAvailableListener(listener);
|
||||||
consumerIdMap.put(consumer, messages[i]);
|
consumerIdMap.put(consumer, message);
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Subscribed: "+consumer+" to "+destination+" id="+messages[i]);
|
log.debug("Subscribed: "+consumer+" to "+destination+" id="+message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ("unlisten".equals(type))
|
else if ("unlisten".equals(type))
|
||||||
|
@ -161,13 +170,13 @@ public class MessageListenerServlet extends MessageServletSupport {
|
||||||
}
|
}
|
||||||
else if ("send".equals(type))
|
else if ("send".equals(type))
|
||||||
{
|
{
|
||||||
TextMessage message = client.getSession().createTextMessage(messages[i]);
|
TextMessage text = client.getSession().createTextMessage(message);
|
||||||
appendParametersToMessage(request, message);
|
appendParametersToMessage(request, text);
|
||||||
|
|
||||||
client.send(destination, message);
|
client.send(destination, text);
|
||||||
message_ids+=message.getJMSMessageID()+"\n";
|
message_ids+=text.getJMSMessageID()+"\n";
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Sent "+messages[i]+" to "+destination);
|
log.debug("Sent "+message+" to "+destination);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -147,7 +147,14 @@ var amq =
|
||||||
{
|
{
|
||||||
if (amq._queueMessages>0)
|
if (amq._queueMessages>0)
|
||||||
{
|
{
|
||||||
amq._messageQueue+=(amq._messages==0?'destination=':'&destination=')+destination+'&message='+message+'&type='+type;
|
if (amq._messages==0)
|
||||||
|
{
|
||||||
|
amq._messageQueue='destination='+destination+'&message='+message+'&type='+type;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
amq._messageQueue='d'+amq._messages+'='+destination+'&m'+amq._messages+'='+message+'&t'+amq._messages+'='+type;
|
||||||
|
}
|
||||||
amq._messages++;
|
amq._messages++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue