Search in sources :

Example 41 with RoutingType

use of org.apache.activemq.artemis.api.core.RoutingType in project activemq-artemis by apache.

the class StompTest method testPrefix.

public void testPrefix(final String prefix, final RoutingType routingType, final boolean send) throws Exception {
    int port = 61614;
    URI uri = createStompClientUri(scheme, hostname, port);
    final String ADDRESS = UUID.randomUUID().toString();
    final String PREFIXED_ADDRESS = prefix + ADDRESS;
    String param = routingType.toString();
    String urlParam = param.toLowerCase() + "Prefix";
    server.getActiveMQServer().getRemotingService().createAcceptor("test", "tcp://" + hostname + ":" + port + "?protocols=" + StompProtocolManagerFactory.STOMP_PROTOCOL_NAME + "&" + urlParam + "=" + prefix).start();
    StompClientConnection conn = StompClientConnectionFactory.createClientConnection(uri);
    conn.connect(defUser, defPass);
    // since this queue doesn't exist the broker should create a new address using the routing type matching the prefix
    if (send) {
        send(conn, PREFIXED_ADDRESS, null, "Hello World", true);
    } else {
        String uuid = UUID.randomUUID().toString();
        ClientStompFrame frame = conn.createFrame(Stomp.Commands.SUBSCRIBE).addHeader(Stomp.Headers.Subscribe.DESTINATION, PREFIXED_ADDRESS).addHeader(Stomp.Headers.RECEIPT_REQUESTED, uuid);
        frame = conn.sendFrame(frame);
        assertEquals(uuid, frame.getHeader(Stomp.Headers.Response.RECEIPT_ID));
    }
    AddressInfo addressInfo = server.getActiveMQServer().getAddressInfo(SimpleString.toSimpleString(ADDRESS));
    assertNotNull("No address was created with the name " + ADDRESS, addressInfo);
    Set<RoutingType> routingTypes = new HashSet<>();
    routingTypes.add(RoutingType.valueOf(param));
    assertEquals(routingTypes, addressInfo.getRoutingTypes());
    conn.disconnect();
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) StompClientConnection(org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) URI(java.net.URI) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) RoutingType(org.apache.activemq.artemis.api.core.RoutingType) HashSet(java.util.HashSet)

Example 42 with RoutingType

use of org.apache.activemq.artemis.api.core.RoutingType in project activemq-artemis by apache.

the class UpdateQueueTest method testUpdateAddress.

@Test
public void testUpdateAddress() throws Exception {
    ActiveMQServer server = createServer(true, true);
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
    server.start();
    SimpleString ADDRESS = SimpleString.toSimpleString("queue.0");
    AddressInfo infoAdded = new AddressInfo(ADDRESS, RoutingType.ANYCAST);
    server.addAddressInfo(infoAdded);
    server.updateAddressInfo(ADDRESS, infoAdded.getRoutingTypes());
    server.stop();
    server.start();
    AddressInfo infoAfterRestart = server.getPostOffice().getAddressInfo(ADDRESS);
    Assert.assertEquals(infoAdded.getId(), infoAfterRestart.getId());
    EnumSet<RoutingType> completeSet = EnumSet.allOf(RoutingType.class);
    server.updateAddressInfo(ADDRESS, completeSet);
    server.stop();
    server.start();
    infoAfterRestart = server.getPostOffice().getAddressInfo(ADDRESS);
    // it was changed.. so new ID
    Assert.assertNotEquals(infoAdded.getId(), infoAfterRestart.getId());
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) RoutingType(org.apache.activemq.artemis.api.core.RoutingType) Test(org.junit.Test)

Example 43 with RoutingType

use of org.apache.activemq.artemis.api.core.RoutingType in project activemq-artemis by apache.

the class AddressControlTest method testGetRoutingTypes.

@Test
public void testGetRoutingTypes() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    session.createAddress(address, RoutingType.ANYCAST, false);
    AddressControl addressControl = createManagementControl(address);
    String[] routingTypes = addressControl.getRoutingTypes();
    Assert.assertEquals(1, routingTypes.length);
    Assert.assertEquals(RoutingType.ANYCAST.toString(), routingTypes[0]);
    address = RandomUtil.randomSimpleString();
    EnumSet<RoutingType> types = EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST);
    session.createAddress(address, types, false);
    addressControl = createManagementControl(address);
    routingTypes = addressControl.getRoutingTypes();
    Set<String> strings = new HashSet<>(Arrays.asList(routingTypes));
    Assert.assertEquals(2, strings.size());
    Assert.assertTrue(strings.contains(RoutingType.ANYCAST.toString()));
    Assert.assertTrue(strings.contains(RoutingType.MULTICAST.toString()));
}
Also used : AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) RandomUtil.randomString(org.apache.activemq.artemis.tests.util.RandomUtil.randomString) JsonString(javax.json.JsonString) RoutingType(org.apache.activemq.artemis.api.core.RoutingType) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 44 with RoutingType

use of org.apache.activemq.artemis.api.core.RoutingType in project activemq-artemis by apache.

the class AMQPSessionCallback method serverSend.

public void serverSend(final ProtonServerReceiverContext context, final Transaction transaction, final Receiver receiver, final Delivery delivery, SimpleString address, int messageFormat, byte[] data) throws Exception {
    AMQPMessage message = new AMQPMessage(messageFormat, data, coreMessageObjectPools);
    if (address != null) {
        message.setAddress(address);
    } else {
        // Anonymous relay must set a To value
        address = message.getAddressSimpleString();
        if (address == null) {
            rejectMessage(delivery, Symbol.valueOf("failed"), "Missing 'to' field for message sent to an anonymous producer");
            return;
        }
    }
    // here check queue-autocreation
    RoutingType routingType = context.getRoutingType(receiver, address);
    if (!bindingQuery(address, routingType)) {
        throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.addressDoesntExist();
    }
    OperationContext oldcontext = recoverContext();
    try {
        PagingStore store = manager.getServer().getPagingManager().getPageStore(message.getAddressSimpleString());
        if (store.isRejectingMessages()) {
            // We drop pre-settled messages (and abort any associated Tx)
            if (delivery.remotelySettled()) {
                if (transaction != null) {
                    String amqpAddress = delivery.getLink().getTarget().getAddress();
                    ActiveMQException e = new ActiveMQAMQPResourceLimitExceededException("Address is full: " + amqpAddress);
                    transaction.markAsRollbackOnly(e);
                }
            } else {
                rejectMessage(delivery, AmqpError.RESOURCE_LIMIT_EXCEEDED, "Address is full: " + address);
            }
        } else {
            serverSend(transaction, message, delivery, receiver);
        }
    } finally {
        resetContext(oldcontext);
    }
}
Also used : OperationContext(org.apache.activemq.artemis.core.persistence.OperationContext) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQAMQPResourceLimitExceededException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPResourceLimitExceededException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) RoutingType(org.apache.activemq.artemis.api.core.RoutingType)

Example 45 with RoutingType

use of org.apache.activemq.artemis.api.core.RoutingType in project activemq-artemis by apache.

the class ProtonServerReceiverContext method initialise.

@Override
public void initialise() throws Exception {
    super.initialise();
    org.apache.qpid.proton.amqp.messaging.Target target = (org.apache.qpid.proton.amqp.messaging.Target) receiver.getRemoteTarget();
    // Match the settlement mode of the remote instead of relying on the default of MIXED.
    receiver.setSenderSettleMode(receiver.getRemoteSenderSettleMode());
    // We don't currently support SECOND so enforce that the answer is anlways FIRST
    receiver.setReceiverSettleMode(ReceiverSettleMode.FIRST);
    RoutingType defRoutingType;
    if (target != null) {
        if (target.getDynamic()) {
            // if dynamic we have to create the node (queue) and set the address on the target, the node is temporary and
            // will be deleted on closing of the session
            address = SimpleString.toSimpleString(sessionSPI.tempQueueName());
            defRoutingType = getRoutingType(target.getCapabilities(), address);
            try {
                sessionSPI.createTemporaryQueue(address, defRoutingType);
            } catch (ActiveMQSecurityException e) {
                throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.securityErrorCreatingTempDestination(e.getMessage());
            } catch (Exception e) {
                throw new ActiveMQAMQPInternalErrorException(e.getMessage(), e);
            }
            expiryPolicy = target.getExpiryPolicy() != null ? target.getExpiryPolicy() : TerminusExpiryPolicy.LINK_DETACH;
            target.setAddress(address.toString());
        } else {
            // the target will have an address unless the remote is requesting an anonymous
            // relay in which case the address in the incoming message's to field will be
            // matched on receive of the message.
            address = SimpleString.toSimpleString(target.getAddress());
            if (address != null && !address.isEmpty()) {
                defRoutingType = getRoutingType(target.getCapabilities(), address);
                try {
                    if (!sessionSPI.bindingQuery(address, defRoutingType)) {
                        throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.addressDoesntExist();
                    }
                } catch (ActiveMQAMQPNotFoundException e) {
                    throw e;
                } catch (Exception e) {
                    log.debug(e.getMessage(), e);
                    throw new ActiveMQAMQPInternalErrorException(e.getMessage(), e);
                }
                try {
                    sessionSPI.check(address, CheckType.SEND, new SecurityAuth() {

                        @Override
                        public String getUsername() {
                            String username = null;
                            SASLResult saslResult = connection.getSASLResult();
                            if (saslResult != null) {
                                username = saslResult.getUser();
                            }
                            return username;
                        }

                        @Override
                        public String getPassword() {
                            String password = null;
                            SASLResult saslResult = connection.getSASLResult();
                            if (saslResult != null) {
                                if (saslResult instanceof PlainSASLResult) {
                                    password = ((PlainSASLResult) saslResult).getPassword();
                                }
                            }
                            return password;
                        }

                        @Override
                        public RemotingConnection getRemotingConnection() {
                            return connection.connectionCallback.getProtonConnectionDelegate();
                        }
                    });
                } catch (ActiveMQSecurityException e) {
                    throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.securityErrorCreatingProducer(e.getMessage());
                }
            }
        }
        Symbol[] remoteDesiredCapabilities = receiver.getRemoteDesiredCapabilities();
        if (remoteDesiredCapabilities != null) {
            List<Symbol> list = Arrays.asList(remoteDesiredCapabilities);
            if (list.contains(AmqpSupport.DELAYED_DELIVERY)) {
                receiver.setOfferedCapabilities(new Symbol[] { AmqpSupport.DELAYED_DELIVERY });
            }
        }
    }
    flow(amqpCredits, minCreditRefresh);
}
Also used : ActiveMQAMQPInternalErrorException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException) Symbol(org.apache.qpid.proton.amqp.Symbol) SecurityAuth(org.apache.activemq.artemis.core.security.SecurityAuth) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) PlainSASLResult(org.apache.activemq.artemis.protocol.amqp.sasl.PlainSASLResult) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQAMQPNotFoundException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPNotFoundException) ActiveMQAMQPInternalErrorException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException) ActiveMQAMQPNotFoundException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPNotFoundException) ActiveMQAMQPException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException) ActiveMQSecurityException(org.apache.activemq.artemis.api.core.ActiveMQSecurityException) SASLResult(org.apache.activemq.artemis.protocol.amqp.sasl.SASLResult) PlainSASLResult(org.apache.activemq.artemis.protocol.amqp.sasl.PlainSASLResult) ActiveMQSecurityException(org.apache.activemq.artemis.api.core.ActiveMQSecurityException) 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