Search in sources :

Example 21 with RoutingType

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));
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) RoutingType(org.apache.activemq.artemis.api.core.RoutingType) Test(org.junit.Test)

Example 22 with RoutingType

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());
}
Also used : AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) RoutingType(org.apache.activemq.artemis.api.core.RoutingType) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 23 with RoutingType

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));
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageProducer(javax.jms.MessageProducer) Topic(javax.jms.Topic) Queue(javax.jms.Queue) RoutingType(org.apache.activemq.artemis.api.core.RoutingType) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Session(javax.jms.Session) Test(org.junit.Test)

Example 24 with RoutingType

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;
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) RoutingStatus(org.apache.activemq.artemis.core.postoffice.RoutingStatus) RoutingType(org.apache.activemq.artemis.api.core.RoutingType)

Example 25 with RoutingType

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();
}
Also used : RoutingType(org.apache.activemq.artemis.api.core.RoutingType)

Aggregations

RoutingType (org.apache.activemq.artemis.api.core.RoutingType)45 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)31 Test (org.junit.Test)15 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)11 AddressInfo (org.apache.activemq.artemis.core.server.impl.AddressInfo)11 HashSet (java.util.HashSet)9 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)9 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)8 QueueQueryResult (org.apache.activemq.artemis.core.server.QueueQueryResult)7 OperationContext (org.apache.activemq.artemis.core.persistence.OperationContext)6 ServerSession (org.apache.activemq.artemis.core.server.ServerSession)6 QueueBinding (org.apache.activemq.artemis.core.postoffice.QueueBinding)5 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)5 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)4 Semaphore (java.util.concurrent.Semaphore)4 Pair (org.apache.activemq.artemis.api.core.Pair)4 CoreAddressConfiguration (org.apache.activemq.artemis.core.config.CoreAddressConfiguration)4 CoreQueueConfiguration (org.apache.activemq.artemis.core.config.CoreQueueConfiguration)4 Filter (org.apache.activemq.artemis.core.filter.Filter)4 PageSubscription (org.apache.activemq.artemis.core.paging.cursor.PageSubscription)4