https://issues.apache.org/jira/browse/AMQ-4522 - set timeToLive when sending a message using JMX

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1480189 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Bosanac Dejan 2013-05-08 09:15:17 +00:00
parent ff9b80040b
commit fc8c8d339e
3 changed files with 12 additions and 4 deletions

View File

@ -299,7 +299,7 @@ public class DestinationView implements DestinationViewMBean {
}
@Override
public String sendTextMessage(Map headers, String body, String userName, String password) throws Exception {
public String sendTextMessage(Map<String, String> headers, String body, String userName, String password) throws Exception {
String brokerUrl = "vm://" + broker.getBrokerName();
ActiveMQDestination dest = destination.getActiveMQDestination();
@ -320,7 +320,15 @@ public class DestinationView implements DestinationViewMBean {
producer.setDeliveryMode(msg.getJMSDeliveryMode());
producer.setPriority(msg.getPriority());
long ttl = msg.getExpiration() - System.currentTimeMillis();
long ttl = 0;
if (msg.getExpiration() != 0) {
ttl = msg.getExpiration() - System.currentTimeMillis();
} else {
String timeToLive = headers.get("timeToLive");
if (timeToLive != null) {
ttl = Integer.valueOf(timeToLive);
}
}
producer.setTimeToLive(ttl > 0 ? ttl : 0);
producer.send(msg);

View File

@ -181,7 +181,7 @@ public interface DestinationViewMBean {
* @throws Exception
*/
@MBeanInfo("Sends a TextMessage to a password-protected destination.")
String sendTextMessage(@MBeanInfo("headers") Map<?,?> headers, @MBeanInfo("body") String body, @MBeanInfo("user") String user, @MBeanInfo("password") String password) throws Exception;
String sendTextMessage(@MBeanInfo("headers") Map<String,String> headers, @MBeanInfo("body") String body, @MBeanInfo("user") String user, @MBeanInfo("password") String password) throws Exception;
/**
* @return the percentage of amount of memory used
*/

View File

@ -79,7 +79,7 @@ public class SecurityJMXTest extends TestCase {
"destinationType=Queue,destinationName=TEST.Q");
QueueViewMBean queueMbean = MBeanServerInvocationHandler.newProxyInstance(connection, name, QueueViewMBean.class, true);
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("JMSExpiration", Long.toString(System.currentTimeMillis() + 2000));
headers.put("timeToLive", Long.toString(2000));
headers.put("JMSDeliveryMode", Integer.toString(DeliveryMode.PERSISTENT));
queueMbean.sendTextMessage(headers, "test", "system", "manager");
// allow message to expire on the queue