本文整理汇总了Java中org.apache.activemq.command.ActiveMQDestination类的典型用法代码示例。如果您正苦于以下问题:Java ActiveMQDestination类的具体用法?Java ActiveMQDestination怎么用?Java ActiveMQDestination使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ActiveMQDestination类属于org.apache.activemq.command包,在下文中一共展示了ActiveMQDestination类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addConsumer
import org.apache.activemq.command.ActiveMQDestination; //导入依赖的package包/类
/**
* Add new message consumer.
*
* @param context
* @param info
* @return
* @throws Exception
* @see org.apache.activemq.broker.BrokerFilter#addConsumer(org.apache.activemq.broker.ConnectionContext, org.apache.activemq.command.ConsumerInfo)
*/
public Subscription addConsumer(ConnectionContext context, ConsumerInfo info) throws Exception {
ActiveMQDestination dest = info.getDestination();
Connection conn = context.getConnection();
if (dest != null) {
String destName = info.getDestination().getPhysicalName();
String clientId = context.getClientId();
String allowedDest = userMap.get(clientId);
logger.info(">>> Got Consumer Add request { Destination: " + destName
+ ", Remote Address: " + conn.getRemoteAddress()
+ ", ClientID: " + clientId
+ " }");
if (allowedDest != null && (allowedDest.equals("*") || allowedDest.equals(destName) || destName.startsWith("ActiveMQ"))) {
logger.info(">>> Subscription allowed");
} else {
logger.error(">>> Destination not allowed. Subscription denied!");
throw new CmsAuthException(">>> Subscription denied!");
}
} else {
logger.error("<<< Got Consumer Add request from Remote Address:" + conn.getRemoteAddress() + ". But destination is NULL.");
}
return super.addConsumer(context, info);
}
示例2: addProducer
import org.apache.activemq.command.ActiveMQDestination; //导入依赖的package包/类
/**
* Add message producer.
*
* @param context
* @param info
* @throws Exception
* @see org.apache.activemq.broker.BrokerFilter#addProducer(org.apache.activemq.broker.ConnectionContext, org.apache.activemq.command.ProducerInfo)
*/
public void addProducer(ConnectionContext context, ProducerInfo info) throws Exception {
Connection conn = context.getConnection();
ActiveMQDestination dest = info.getDestination();
if (dest != null) {
String destName = dest.getPhysicalName();
String clientId = context.getClientId();
logger.info(">>> Got Producer Add request { Destination: " + destName
+ ", Remote Address: " + conn.getRemoteAddress()
+ ", ClientID: " + clientId
+ " }");
String allowedDest = userMap.get(context.getClientId());
if (allowedDest != null && (allowedDest.equals("*") || "controller.response".equals(destName))) {
logger.info("<<< Producer allowed");
} else {
logger.error("<<< Destination not allowed. Producer denied!");
throw new CmsAuthException("<<< Producer denied!");
}
} else {
logger.error("<<< Got Producer Add request from Remote Address:" + conn.getRemoteAddress() + ". But destination is NULL.");
}
super.addProducer(context, info);
}
示例3: addConsumerTest
import org.apache.activemq.command.ActiveMQDestination; //导入依赖的package包/类
@Test(priority=5)
public void addConsumerTest(){
//set up a mock for ConsumerInfo
ActiveMQDestination activeMQDestinationMQ = ActiveMQDestination.createDestination("mockMQDestionation", (byte) 1 );
activeMQDestinationMQ.setPhysicalName(MQ_PHYSICAL_NAME);
ConsumerInfo consumerInfoActiveMQ = mock(ConsumerInfo.class);
when(consumerInfoActiveMQ.getDestination()).thenReturn(activeMQDestinationMQ);
//set up mock for ProducerInfo
producerInfo = mock(ProducerInfo.class);
when(producerInfo.getDestination()).thenReturn(activeMQDestination);
try {
this.oneopsAuthBroker.addConsumer(connectionContextMock, consumerInfoActiveMQ);
} catch (Exception e) {
logger.warn("caught exception, make sure Broker is mocked",e);
throw new RuntimeException(e);
}
}
示例4: TestLifeCycle
import org.apache.activemq.command.ActiveMQDestination; //导入依赖的package包/类
@Inject
public TestLifeCycle(JmsConnection jmsConnection, Destination resultsDestination,
SuiteExecutor suiteExecutor,
SuiteIndexWrapper suite)
throws JMSException {
this.suiteExecutor = suiteExecutor;
this.suite = suite;
if (resultsDestination instanceof ActiveMQDestination) {
ActiveMQTopic advisoryTopic = AdvisorySupport.getConsumerAdvisoryTopic(resultsDestination);
session = jmsConnection.getJmsSession();
topicConsumer = session.createConsumer(advisoryTopic);
topicConsumer.setMessageListener(this);
} else {
topicConsumer = null;
session = null;
}
}
示例5: destroyMessageQueue
import org.apache.activemq.command.ActiveMQDestination; //导入依赖的package包/类
/**
* Queues are created dynamically, but can must be destroyed explicitly by
* calling this method. Queues with active subscribers cannot be destroyed
* and result in an exception.
*
* @param brokerHost
* @param brokerPort
* @param topic
* @throws JMSException
*/
public static void destroyMessageQueue(final String brokerHost, final String brokerPort, final String topic) throws JMSException {
// Create a ConnectionFactory
final ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(String.format("tcp://%s:%s", brokerHost, brokerPort));
// Create a Connection
final Connection connection = connectionFactory.createConnection();
connection.start();
// Create a Session
final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Create the destination (Topic or Queue), close Handle after that
final Destination destination = session.createQueue(topic);
session.close();
// Destroy Empty Queue And Clean Up
((ActiveMQConnection) connection).destroyDestination((ActiveMQDestination) destination);
connection.close();
}
示例6: destroyMessageQueue
import org.apache.activemq.command.ActiveMQDestination; //导入依赖的package包/类
public static void destroyMessageQueue(String brokerHost, String brokerPort, String topic) throws JMSException {
// Create a ConnectionFactory
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(String.format("tcp://%s:%s", brokerHost, brokerPort));
// Create a Connection
Connection connection = connectionFactory.createConnection();
connection.start();
// Create a Session
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Create the destination (Topic or Queue)
Destination destination = session.createQueue(topic);
session.close();
// Destroy Empty Queue
((ActiveMQConnection) connection).destroyDestination((ActiveMQDestination) destination);
connection.close();
}
示例7: testActiveMQOriginalDestination
import org.apache.activemq.command.ActiveMQDestination; //导入依赖的package包/类
@Test
public void testActiveMQOriginalDestination() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
template.sendBody("activemq:queue:foo", "Hello World");
assertMockEndpointsSatisfied();
// consume from bar
Exchange out = consumer.receive("activemq:queue:bar", 5000);
assertNotNull(out);
// and we should have foo as the original destination
JmsMessage msg = out.getIn(JmsMessage.class);
Message jms = msg.getJmsMessage();
ActiveMQMessage amq = assertIsInstanceOf(ActiveMQMessage.class, jms);
ActiveMQDestination original = amq.getOriginalDestination();
assertNotNull(original);
assertEquals("foo", original.getPhysicalName());
assertEquals("Queue", original.getDestinationTypeAsString());
}
示例8: checkDestinationAdmin
import org.apache.activemq.command.ActiveMQDestination; //导入依赖的package包/类
protected boolean checkDestinationAdmin(SecurityContext securityContext, ActiveMQDestination destination) {
Destination existing = this.getDestinationMap().get(destination);
if (existing != null) {
return true;
}
if (!securityContext.isBrokerContext()) {
Set<?> allowedACLs = null;
if (!destination.isTemporary()) {
allowedACLs = authorizationMap.getAdminACLs(destination);
} else {
allowedACLs = authorizationMap.getTempDestinationAdminACLs();
}
if (allowedACLs != null && !securityContext.isInOneOf(allowedACLs)) {
return false;
}
}
return true;
}
示例9: testSlowConsumerAdvisory
import org.apache.activemq.command.ActiveMQDestination; //导入依赖的package包/类
public void testSlowConsumerAdvisory() throws Exception {
Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryQueue queue = s.createTemporaryQueue();
MessageConsumer consumer = s.createConsumer(queue);
assertNotNull(consumer);
Topic advisoryTopic = AdvisorySupport.getSlowConsumerAdvisoryTopic((ActiveMQDestination) queue);
s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic);
// start throwing messages at the consumer
MessageProducer producer = s.createProducer(queue);
for (int i = 0; i < MESSAGE_COUNT; i++) {
BytesMessage m = s.createBytesMessage();
m.writeBytes(new byte[1024]);
producer.send(m);
}
Message msg = advisoryConsumer.receive(1000);
assertNotNull(msg);
}
示例10: testAddingConsumer
import org.apache.activemq.command.ActiveMQDestination; //导入依赖的package包/类
public void testAddingConsumer() throws Exception {
ActiveMQDestination destination = new ActiveMQQueue("TEST");
// Setup a first connection
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(destination);
//MessageConsumer consumer = session.createConsumer(destination);
TextMessage message = session.createTextMessage("message");
message.setStringProperty("JMSXGroupID", "TEST-GROUP");
LOG.info("sending message: " + message);
producer.send(message);
MessageConsumer consumer = session.createConsumer(destination);
TextMessage msg = (TextMessage) consumer.receive();
assertNotNull(msg);
boolean first = msg.getBooleanProperty("JMSXGroupFirstForConsumer");
assertTrue(first);
}
示例11: testConnectorConfiguredCorrectly
import org.apache.activemq.command.ActiveMQDestination; //导入依赖的package包/类
public void testConnectorConfiguredCorrectly() throws Exception {
TransportConnector connector = brokerService.getTransportConnectors().get(0);
assertEquals(new URI("tcp://localhost:61636"), connector.getUri());
assertTrue(connector.getTaskRunnerFactory() == brokerService.getTaskRunnerFactory());
NetworkConnector netConnector = brokerService.getNetworkConnectors().get(0);
List<ActiveMQDestination> excludedDestinations = netConnector.getExcludedDestinations();
assertEquals(new ActiveMQQueue("exclude.test.foo"), excludedDestinations.get(0));
assertEquals(new ActiveMQTopic("exclude.test.bar"), excludedDestinations.get(1));
List<ActiveMQDestination> dynamicallyIncludedDestinations = netConnector.getDynamicallyIncludedDestinations();
assertEquals(new ActiveMQQueue("include.test.foo"), dynamicallyIncludedDestinations.get(0));
assertEquals(new ActiveMQTopic("include.test.bar"), dynamicallyIncludedDestinations.get(1));
}
示例12: testStartAfterSend
import org.apache.activemq.command.ActiveMQDestination; //导入依赖的package包/类
@Test
public void testStartAfterSend() throws Exception {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
ActiveMQDestination destination = createDestination(session, destinationType);
MessageConsumer consumer = session.createConsumer(destination);
// Send the messages
sendMessages(session, destination, 1);
// Start the conncection after the message was sent.
connection.start();
// Make sure only 1 message was delivered.
assertNotNull(consumer.receive(1000));
assertNull(consumer.receiveNoWait());
}
示例13: send
import org.apache.activemq.command.ActiveMQDestination; //导入依赖的package包/类
/**
*
*/
public void send(ProducerBrokerExchange producerExchange, Message message) throws Exception {
ActiveMQDestination destination = message.getDestination();
if (destination.isComposite()) {
ActiveMQDestination[] destinations = destination.getCompositeDestinations();
for (int i = 0; i < destinations.length; i++) {
if (i != 0) {
message = message.copy();
message.setMemoryUsage(null);
}
message.setOriginalDestination(destination);
message.setDestination(destinations[i]);
next.send(producerExchange, message);
}
} else {
next.send(producerExchange, message);
}
}
示例14: doGetLastAckedDurableSubscriberMessageId
import org.apache.activemq.command.ActiveMQDestination; //导入依赖的package包/类
public long doGetLastAckedDurableSubscriberMessageId(TransactionContext c, ActiveMQDestination destination,
String clientId, String subscriberName) throws SQLException, IOException {
PreparedStatement s = null;
ResultSet rs = null;
long result = -1;
cleanupExclusiveLock.readLock().lock();
try {
s = c.getConnection().prepareStatement(this.statements.getLastAckedDurableSubscriberMessageStatement());
s.setString(1, destination.getQualifiedName());
s.setString(2, clientId);
s.setString(3, subscriberName);
rs = s.executeQuery();
if (rs.next()) {
result = rs.getLong(1);
if (result == 0 && rs.wasNull()) {
result = -1;
}
}
} finally {
cleanupExclusiveLock.readLock().unlock();
close(rs);
close(s);
}
return result;
}
示例15: testAckedMessageAreConsumed
import org.apache.activemq.command.ActiveMQDestination; //导入依赖的package包/类
/**
* Tests if acknowledged messages are being consumed.
*
* @throws JMSException
*/
@Test
public void testAckedMessageAreConsumed() throws JMSException {
connection.start();
Session session = connection.createSession(false, ActiveMQSession.INDIVIDUAL_ACKNOWLEDGE);
Queue queue = (Queue) this.createDestination(session, ActiveMQDestination.QUEUE_TYPE);
MessageProducer producer = session.createProducer(queue);
producer.send(session.createTextMessage("Hello"));
// Consume the message...
MessageConsumer consumer = session.createConsumer(queue);
Message msg = consumer.receive(5000);
assertNotNull(msg);
msg.acknowledge();
// Reset the session.
session.close();
session = connection.createSession(false, ActiveMQSession.INDIVIDUAL_ACKNOWLEDGE);
// Attempt to Consume the message...
consumer = session.createConsumer(queue);
msg = consumer.receive(1000);
assertNull(msg);
session.close();
}