mirror of https://github.com/apache/activemq.git
was having difficulty setting JMSreplyTo on message from jconsole. the header map operation is greyed out. Seems it needs a special ui to populate. I added a simpler csn=v string where body,username,password are special and where all other names are applied as properties. Jconsole can now set a reply to via sendTextMessageWithProperties("body=hi,JMSReplyTo=Queue2"
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1504660 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ae5abf143b
commit
dda5c93cd8
|
@ -20,6 +20,7 @@ import java.io.IOException;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -51,6 +52,8 @@ import org.apache.activemq.command.Message;
|
||||||
import org.apache.activemq.filter.BooleanExpression;
|
import org.apache.activemq.filter.BooleanExpression;
|
||||||
import org.apache.activemq.filter.MessageEvaluationContext;
|
import org.apache.activemq.filter.MessageEvaluationContext;
|
||||||
import org.apache.activemq.selector.SelectorParser;
|
import org.apache.activemq.selector.SelectorParser;
|
||||||
|
import org.apache.activemq.util.IntrospectionSupport;
|
||||||
|
import org.apache.activemq.util.MarshallingSupport;
|
||||||
import org.apache.activemq.util.URISupport;
|
import org.apache.activemq.util.URISupport;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -283,6 +286,19 @@ public class DestinationView implements DestinationViewMBean {
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String sendTextMessageWithProperties(String properties) throws Exception {
|
||||||
|
String[] kvs = properties.split(",");
|
||||||
|
Map<String, String> props = new HashMap<String, String>();
|
||||||
|
for (String kv : kvs) {
|
||||||
|
String[] it = kv.split("=");
|
||||||
|
if (it.length == 2) {
|
||||||
|
props.put(it[0],it[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sendTextMessage(props, props.remove("body"), props.remove("username"), props.remove("password"));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String sendTextMessage(String body) throws Exception {
|
public String sendTextMessage(String body) throws Exception {
|
||||||
return sendTextMessage(Collections.EMPTY_MAP, body);
|
return sendTextMessage(Collections.EMPTY_MAP, body);
|
||||||
|
|
|
@ -147,6 +147,17 @@ public interface DestinationViewMBean {
|
||||||
@MBeanInfo("Sends a TextMessage to the destination.")
|
@MBeanInfo("Sends a TextMessage to the destination.")
|
||||||
String sendTextMessage(@MBeanInfo("body") String body) throws Exception;
|
String sendTextMessage(@MBeanInfo("body") String body) throws Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a TextMessage to the destination.
|
||||||
|
*
|
||||||
|
* @param properties the message properties to set as a comma sep name=value list. Can only
|
||||||
|
* contain Strings maped to primitive types or JMS properties. eg: body=hi,JMSReplyTo=Queue2
|
||||||
|
* @return the message id of the message sent.
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@MBeanInfo("Sends a TextMessage to the destination.")
|
||||||
|
public String sendTextMessageWithProperties(String properties) throws Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a TextMesage to the destination.
|
* Sends a TextMesage to the destination.
|
||||||
*
|
*
|
||||||
|
|
|
@ -92,6 +92,7 @@ public class MBeanTest extends EmbeddedBrokerTestSupport {
|
||||||
// test all the various MBeans now we have a producer, consumer and
|
// test all the various MBeans now we have a producer, consumer and
|
||||||
// messages on a queue
|
// messages on a queue
|
||||||
assertSendViaMBean();
|
assertSendViaMBean();
|
||||||
|
assertSendCsnvViaMBean();
|
||||||
assertQueueBrowseWorks();
|
assertQueueBrowseWorks();
|
||||||
assertCreateAndDestroyDurableSubscriptions();
|
assertCreateAndDestroyDurableSubscriptions();
|
||||||
assertConsumerCounts();
|
assertConsumerCounts();
|
||||||
|
@ -394,6 +395,14 @@ public class MBeanTest extends EmbeddedBrokerTestSupport {
|
||||||
proxy.sendTextMessage(headers, body);
|
proxy.sendTextMessage(headers, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
browseAndVerify(proxy);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void browseAndVerify(QueueViewMBean proxy) throws Exception {
|
||||||
|
browseAndVerifyTypes(proxy, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void browseAndVerifyTypes(QueueViewMBean proxy, boolean allStrings) throws Exception {
|
||||||
CompositeData[] compdatalist = proxy.browse();
|
CompositeData[] compdatalist = proxy.browse();
|
||||||
if (compdatalist.length == 0) {
|
if (compdatalist.length == 0) {
|
||||||
fail("There is no message in the queue:");
|
fail("There is no message in the queue:");
|
||||||
|
@ -418,6 +427,13 @@ public class MBeanTest extends EmbeddedBrokerTestSupport {
|
||||||
}
|
}
|
||||||
assertComplexData(i, cdata, "PropertiesText", expected);
|
assertComplexData(i, cdata, "PropertiesText", expected);
|
||||||
|
|
||||||
|
if (allStrings) {
|
||||||
|
Map stringProperties = CompositeDataHelper.getTabularMap(cdata, CompositeDataConstants.STRING_PROPERTIES);
|
||||||
|
assertEquals("stringProperties size()", 2, stringProperties.size());
|
||||||
|
assertEquals("stringProperties.MyHeader", "StringHeader" + i, stringProperties.get("MyStringHeader"));
|
||||||
|
assertEquals("stringProperties.MyHeader", "" + i, stringProperties.get("MyHeader"));
|
||||||
|
|
||||||
|
} else {
|
||||||
Map intProperties = CompositeDataHelper.getTabularMap(cdata, CompositeDataConstants.INT_PROPERTIES);
|
Map intProperties = CompositeDataHelper.getTabularMap(cdata, CompositeDataConstants.INT_PROPERTIES);
|
||||||
assertEquals("intProperties size()", 1, intProperties.size());
|
assertEquals("intProperties size()", 1, intProperties.size());
|
||||||
assertEquals("intProperties.MyHeader", i, intProperties.get("MyHeader"));
|
assertEquals("intProperties.MyHeader", i, intProperties.get("MyHeader"));
|
||||||
|
@ -425,10 +441,11 @@ public class MBeanTest extends EmbeddedBrokerTestSupport {
|
||||||
Map stringProperties = CompositeDataHelper.getTabularMap(cdata, CompositeDataConstants.STRING_PROPERTIES);
|
Map stringProperties = CompositeDataHelper.getTabularMap(cdata, CompositeDataConstants.STRING_PROPERTIES);
|
||||||
assertEquals("stringProperties size()", 1, stringProperties.size());
|
assertEquals("stringProperties size()", 1, stringProperties.size());
|
||||||
assertEquals("stringProperties.MyHeader", "StringHeader" + i, stringProperties.get("MyStringHeader"));
|
assertEquals("stringProperties.MyHeader", "StringHeader" + i, stringProperties.get("MyStringHeader"));
|
||||||
|
}
|
||||||
|
|
||||||
Map properties = CompositeDataHelper.getMessageUserProperties(cdata);
|
Map properties = CompositeDataHelper.getMessageUserProperties(cdata);
|
||||||
assertEquals("properties size()", 2, properties.size());
|
assertEquals("properties size()", 2, properties.size());
|
||||||
assertEquals("properties.MyHeader", i, properties.get("MyHeader"));
|
assertEquals("properties.MyHeader", allStrings ? "" + i : i, properties.get("MyHeader"));
|
||||||
assertEquals("properties.MyHeader", "StringHeader" + i, properties.get("MyStringHeader"));
|
assertEquals("properties.MyHeader", "StringHeader" + i, properties.get("MyStringHeader"));
|
||||||
|
|
||||||
assertComplexData(i, cdata, "JMSXGroupSeq", 1234);
|
assertComplexData(i, cdata, "JMSXGroupSeq", 1234);
|
||||||
|
@ -437,6 +454,40 @@ public class MBeanTest extends EmbeddedBrokerTestSupport {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void assertSendCsnvViaMBean() throws Exception {
|
||||||
|
String queueName = getDestinationString() + ".SendMBBean";
|
||||||
|
|
||||||
|
ObjectName brokerName = assertRegisteredObjectName(domain + ":type=Broker,brokerName=localhost");
|
||||||
|
echo("Create QueueView MBean...");
|
||||||
|
BrokerViewMBean broker = (BrokerViewMBean)MBeanServerInvocationHandler.newProxyInstance(mbeanServer, brokerName, BrokerViewMBean.class, true);
|
||||||
|
broker.addQueue(queueName);
|
||||||
|
|
||||||
|
ObjectName queueViewMBeanName = assertRegisteredObjectName(domain + ":type=Broker,brokerName=localhost,destinationType=Queue,destinationName=" + queueName);
|
||||||
|
|
||||||
|
echo("Create QueueView MBean...");
|
||||||
|
QueueViewMBean proxy = (QueueViewMBean)MBeanServerInvocationHandler.newProxyInstance(mbeanServer, queueViewMBeanName, QueueViewMBean.class, true);
|
||||||
|
|
||||||
|
proxy.purge();
|
||||||
|
|
||||||
|
int count = 5;
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
String props = "body=message:" + i;
|
||||||
|
|
||||||
|
props += ",JMSCorrelationID=MyCorrId";
|
||||||
|
props += ",JMSDeliveryMode=1";
|
||||||
|
props += ",JMSXGroupID=MyGroupID";
|
||||||
|
props += ",JMSXGroupSeq=1234";
|
||||||
|
props += ",JMSPriority=" + (i + 1);
|
||||||
|
props += ",JMSType=MyType";
|
||||||
|
props += ",MyHeader=" + i;
|
||||||
|
props += ",MyStringHeader=StringHeader" + i;
|
||||||
|
|
||||||
|
proxy.sendTextMessageWithProperties(props);
|
||||||
|
}
|
||||||
|
|
||||||
|
browseAndVerifyTypes(proxy, true);
|
||||||
|
}
|
||||||
|
|
||||||
protected void assertComplexData(int messageIndex, CompositeData cdata, String name, Object expected) {
|
protected void assertComplexData(int messageIndex, CompositeData cdata, String name, Object expected) {
|
||||||
Object value = cdata.get(name);
|
Object value = cdata.get(name);
|
||||||
assertEquals("Message " + messageIndex + " CData field: " + name, expected, value);
|
assertEquals("Message " + messageIndex + " CData field: " + name, expected, value);
|
||||||
|
|
Loading…
Reference in New Issue