use of org.apache.activemq.artemis.api.core.RoutingType in project activemq-artemis by apache.
the class RoutingTest method testMulticastMessageRoutingExclusivity.
@Test
public void testMulticastMessageRoutingExclusivity() throws Exception {
ClientSession sendSession = cf.createSession(false, true, true);
EnumSet<RoutingType> routingTypes = EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST);
sendSession.createAddress(addressA, routingTypes, false);
sendSession.createQueue(addressA, RoutingType.ANYCAST, queueA);
sendSession.createQueue(addressA, RoutingType.MULTICAST, queueB);
sendSession.createQueue(addressA, RoutingType.MULTICAST, queueC);
ClientProducer p = sendSession.createProducer(addressA);
ClientMessage message = sendSession.createMessage(false);
message.setRoutingType(RoutingType.MULTICAST);
p.send(message);
sendSession.close();
assertTrue(Wait.waitFor(() -> server.locateQueue(queueA).getMessageCount() == 0));
assertTrue(Wait.waitFor(() -> server.locateQueue(queueB).getMessageCount() + server.locateQueue(queueC).getMessageCount() == 2));
}
use of org.apache.activemq.artemis.api.core.RoutingType in project activemq-artemis by apache.
the class AddressConfigTest method persistAddressConfigTest.
@Test
public void persistAddressConfigTest() throws Exception {
server.createQueue(SimpleString.toSimpleString("myAddress"), RoutingType.MULTICAST, SimpleString.toSimpleString("myQueue"), null, true, false);
server.stop();
server.start();
AddressInfo addressInfo = server.getAddressInfo(SimpleString.toSimpleString("myAddress"));
assertNotNull(addressInfo);
Set<RoutingType> routingTypeSet = new HashSet<>();
routingTypeSet.add(RoutingType.MULTICAST);
assertEquals(routingTypeSet, addressInfo.getRoutingTypes());
}
use of org.apache.activemq.artemis.api.core.RoutingType in project activemq-artemis by apache.
the class MessageProducerTest method testSendToQueueOnlyWhenTopicWithSameAddress.
@Test
public void testSendToQueueOnlyWhenTopicWithSameAddress() throws Exception {
SimpleString addr = SimpleString.toSimpleString("testAddr");
EnumSet<RoutingType> supportedRoutingTypes = EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST);
servers.get(0).getActiveMQServer().addAddressInfo(new AddressInfo(addr, supportedRoutingTypes));
servers.get(0).getActiveMQServer().createQueue(addr, RoutingType.ANYCAST, addr, null, false, false);
Connection pconn = createConnection();
pconn.start();
Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = ps.createQueue(addr.toString());
Topic topic = ps.createTopic(addr.toString());
MessageConsumer queueConsumer = ps.createConsumer(queue);
MessageConsumer topicConsumer = ps.createConsumer(topic);
MessageProducer queueProducer = ps.createProducer(queue);
queueProducer.send(ps.createMessage());
assertNotNull(queueConsumer.receive(1000));
assertNull(topicConsumer.receive(1000));
MessageProducer topicProducer = ps.createProducer(topic);
topicProducer.send(ps.createMessage());
assertNull(queueConsumer.receive(1000));
assertNotNull(topicConsumer.receive(1000));
}
use of org.apache.activemq.artemis.api.core.RoutingType in project activemq-artemis by apache.
the class ServerSessionImpl method doSend.
@Override
public synchronized RoutingStatus doSend(final Transaction tx, final Message msg, final SimpleString originalAddress, final boolean direct, final boolean noAutoCreateQueue) throws Exception {
RoutingStatus result = RoutingStatus.OK;
RoutingType routingType = msg.getRoutingType();
/* TODO-now: How to address here with AMQP?
if (originalAddress != null) {
if (originalAddress.toString().startsWith("anycast:")) {
routingType = RoutingType.ANYCAST;
} else if (originalAddress.toString().startsWith("multicast:")) {
routingType = RoutingType.MULTICAST;
}
} */
AddressInfo art = getAddressAndRoutingType(new AddressInfo(msg.getAddressSimpleString(), routingType));
// check the user has write access to this address.
try {
securityCheck(art.getName(), CheckType.SEND, this);
} catch (ActiveMQException e) {
if (!autoCommitSends && tx != null) {
tx.markAsRollbackOnly(e);
}
throw e;
}
if (server.getConfiguration().isPopulateValidatedUser() && validatedUser != null) {
msg.setValidatedUserID(validatedUser);
}
if (tx == null || autoCommitSends) {
} else {
routingContext.setTransaction(tx);
}
try {
routingContext.setAddress(art.getName());
routingContext.setRoutingType(art.getRoutingType());
result = postOffice.route(msg, routingContext, direct);
Pair<Object, AtomicLong> value = targetAddressInfos.get(msg.getAddressSimpleString());
if (value == null) {
targetAddressInfos.put(msg.getAddressSimpleString(), new Pair<>(msg.getUserID(), new AtomicLong(1)));
} else {
value.setA(msg.getUserID());
value.getB().incrementAndGet();
}
} finally {
routingContext.clear();
}
return result;
}
use of org.apache.activemq.artemis.api.core.RoutingType in project activemq-artemis by apache.
the class AddressInfo method toString.
@Override
public String toString() {
StringBuffer buff = new StringBuffer();
buff.append("Address [name=" + name);
buff.append(", id=" + id);
buff.append(", routingTypes={");
for (RoutingType routingType : routingTypes) {
buff.append(routingType.toString() + ",");
}
// delete hanging comma
if (buff.charAt(buff.length() - 1) == ',') {
buff.deleteCharAt(buff.length() - 1);
}
buff.append("}");
buff.append(", autoCreated=" + autoCreated);
buff.append("]");
return buff.toString();
}
Aggregations