mirror of https://github.com/apache/activemq.git
https://issues.apache.org/activemq/browse/AMQ-2970 - advisory and jmx create/delete destination
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1021425 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0d47fea17c
commit
17851fac05
|
@ -242,20 +242,20 @@ public class BrokerView implements BrokerViewMBean {
|
|||
}
|
||||
|
||||
public void addTopic(String name) throws Exception {
|
||||
broker.addDestination(getConnectionContext(broker.getContextBroker()), new ActiveMQTopic(name),true);
|
||||
broker.getContextBroker().addDestination(getConnectionContext(broker.getContextBroker()), new ActiveMQTopic(name),true);
|
||||
}
|
||||
|
||||
public void addQueue(String name) throws Exception {
|
||||
broker.addDestination(getConnectionContext(broker.getContextBroker()), new ActiveMQQueue(name),true);
|
||||
broker.getContextBroker().addDestination(getConnectionContext(broker.getContextBroker()), new ActiveMQQueue(name),true);
|
||||
}
|
||||
|
||||
public void removeTopic(String name) throws Exception {
|
||||
broker.removeDestination(getConnectionContext(broker.getContextBroker()), new ActiveMQTopic(name),
|
||||
broker.getContextBroker().removeDestination(getConnectionContext(broker.getContextBroker()), new ActiveMQTopic(name),
|
||||
1000);
|
||||
}
|
||||
|
||||
public void removeQueue(String name) throws Exception {
|
||||
broker.removeDestination(getConnectionContext(broker.getContextBroker()), new ActiveMQQueue(name),
|
||||
broker.getContextBroker().removeDestination(getConnectionContext(broker.getContextBroker()), new ActiveMQQueue(name),
|
||||
1000);
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,10 @@ import org.apache.activemq.command.ProducerInfo;
|
|||
import org.apache.activemq.command.RemoveInfo;
|
||||
import org.apache.activemq.command.SessionInfo;
|
||||
|
||||
import javax.management.remote.JMXConnector;
|
||||
import javax.management.remote.JMXConnectorFactory;
|
||||
import javax.management.remote.JMXServiceURL;
|
||||
|
||||
public class AdvisoryBrokerTest extends BrokerTestSupport {
|
||||
|
||||
public void testConnectionAdvisories() throws Exception {
|
||||
|
|
|
@ -0,0 +1,88 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.broker.advisory;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.EmbeddedBrokerTestSupport;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.broker.jmx.BrokerViewMBean;
|
||||
import org.apache.activemq.broker.jmx.ManagementContext;
|
||||
import org.apache.activemq.broker.jmx.QueueViewMBean;
|
||||
import org.apache.activemq.command.ActiveMQMessage;
|
||||
import org.apache.activemq.command.DestinationInfo;
|
||||
|
||||
import javax.jms.*;
|
||||
import javax.management.MBeanServerConnection;
|
||||
import javax.management.MBeanServerInvocationHandler;
|
||||
import javax.management.ObjectName;
|
||||
import javax.management.remote.JMXConnector;
|
||||
import javax.management.remote.JMXConnectorFactory;
|
||||
import javax.management.remote.JMXServiceURL;
|
||||
|
||||
public class AdvisoryJmxTest extends EmbeddedBrokerTestSupport {
|
||||
|
||||
protected BrokerService createBroker() throws Exception {
|
||||
BrokerService answer = new BrokerService();
|
||||
answer.setPersistent(isPersistent());
|
||||
answer.addConnector(bindAddress);
|
||||
ManagementContext context = new ManagementContext();
|
||||
context.setConnectorPort(1199);
|
||||
answer.setManagementContext(context);
|
||||
return answer;
|
||||
}
|
||||
|
||||
public void testCreateDeleteDestinations() throws Exception {
|
||||
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1199/jmxrmi");
|
||||
JMXConnector connector = JMXConnectorFactory.connect(url, null);
|
||||
connector.connect();
|
||||
MBeanServerConnection connection = connector.getMBeanServerConnection();
|
||||
ObjectName name = new ObjectName("org.apache.activemq:Type=Broker,BrokerName=localhost");
|
||||
BrokerViewMBean brokerMbean = (BrokerViewMBean) MBeanServerInvocationHandler.newProxyInstance(connection, name, BrokerViewMBean.class, true);
|
||||
Connection conn = createConnection();
|
||||
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
MessageConsumer consumer = sess.createConsumer(sess.createTopic("ActiveMQ.Advisory.Queue"));
|
||||
conn.start();
|
||||
Destination dest = sess.createQueue("test");
|
||||
|
||||
brokerMbean.addQueue("test");
|
||||
|
||||
ActiveMQMessage msg = (ActiveMQMessage)consumer.receive(1000);
|
||||
assertNotNull(msg);
|
||||
assertTrue(msg.getDataStructure() instanceof DestinationInfo);
|
||||
assertEquals(((DestinationInfo)msg.getDataStructure()).getDestination(), dest);
|
||||
assertEquals(((DestinationInfo)msg.getDataStructure()).getOperationType(), 0);
|
||||
|
||||
brokerMbean.removeQueue("test");
|
||||
|
||||
msg = (ActiveMQMessage)consumer.receive(1000);
|
||||
assertNotNull(msg);
|
||||
assertTrue(msg.getDataStructure() instanceof DestinationInfo);
|
||||
assertEquals(((DestinationInfo)msg.getDataStructure()).getDestination(), dest);
|
||||
assertEquals(((DestinationInfo)msg.getDataStructure()).getOperationType(), 1);
|
||||
|
||||
|
||||
brokerMbean.addQueue("test");
|
||||
msg = (ActiveMQMessage)consumer.receive(1000);
|
||||
assertNotNull(msg);
|
||||
assertTrue(msg.getDataStructure() instanceof DestinationInfo);
|
||||
assertEquals(((DestinationInfo)msg.getDataStructure()).getDestination(), dest);
|
||||
assertEquals(((DestinationInfo)msg.getDataStructure()).getOperationType(), 0);
|
||||
assertEquals(((DestinationInfo)msg.getDataStructure()).getOperationType(), 0);
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue