Search in sources :

Example 26 with Exchange

use of org.apache.qpid.server.model.Exchange in project qpid by apache.

the class Queue method mapEncode.

/**
 * This method maps the org.apache.qpid.server.model.Queue to QMF2 broker properties where possible then
 * serialises into the underlying Map for transmission via AMQP. This method is called by handleQueryRequest()
 * in the org.apache.qpid.qmf2.agent.Agent class implementing the main QMF2 Agent behaviour.
 *
 * @return the underlying map.
 */
@Override
public Map<String, Object> mapEncode() {
    // too late to populate the "altEx" property of the queueDeclareEvent.
    if (_alternateExchange == null) {
        Exchange altEx = _queue.getAlternateExchange();
        if (altEx != null) {
            _alternateExchangeName = _vhostName + altEx.getName();
            _alternateExchange = new ObjectId("", "org.apache.qpid.broker:exchange:" + _alternateExchangeName, 0);
            setRefValue("altExchange", _alternateExchange);
        }
    }
    // Statistics
    setValue("msgTotalEnqueues", _queue.getTotalEnqueuedMessages());
    setValue("msgTotalDequeues", _queue.getTotalDequeuedMessages());
    // msgTxnEnqueues not implemented in Java Broker
    // msgTxnDequeues not implemented in Java Broker
    setValue("msgPersistEnqueues", _queue.getPersistentEnqueuedMessages());
    setValue("msgPersistDequeues", _queue.getPersistentDequeuedMessages());
    setValue("msgDepth", _queue.getQueueDepthMessages());
    setValue("byteDepth", _queue.getQueueDepthBytes());
    setValue("byteTotalEnqueues", _queue.getTotalEnqueuedBytes());
    setValue("byteTotalDequeues", _queue.getTotalDequeuedBytes());
    // byteTxnEnqueues not implemented in Java Broker
    // byteTxnDequeues not implemented in Java Broker
    setValue("bytePersistEnqueues", _queue.getPersistentEnqueuedBytes());
    setValue("bytePersistDequeues", _queue.getPersistentDequeuedBytes());
    // Flow-to-disk Statistics not implemented in Java Broker
    // releases & acquires not implemented in Java Broker
    // discardsTtl (discardsTtlMessages) not implemented in Java Broker
    // discardsRing not implemented in Java Broker
    // discardsLvq not implemented in Java Broker
    // discardsOverflow not implemented in Java Broker
    // discardsSubscriber not implemented in Java Broker
    // discardsPurge not implemented in Java Broker
    // reroutes not implemented in Java Broker
    setValue("consumerCount", _queue.getConsumerCount());
    setValue("bindingCount", _queue.getBindingCount());
    setValue("unackedMessages", _queue.getUnacknowledgedMessages());
    setValue("messageLatency", "Not yet implemented");
    // flowStopped not implemented in Java Broker
    // flowStoppedCount not implemented in Java Broker
    // TODO only update if statistics have actually changed.
    update();
    return super.mapEncode();
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) ObjectId(org.apache.qpid.qmf2.common.ObjectId)

Example 27 with Exchange

use of org.apache.qpid.server.model.Exchange in project qpid-broker-j by apache.

the class PropertyConverter_1_0_to_0_8Test method testToConversionWhenExchangeIsSpecified.

@Test
public void testToConversionWhenExchangeIsSpecified() {
    final String testExchange = "testExchange";
    Properties properties = new Properties();
    properties.setTo(testExchange);
    Message_1_0 message = createTestMessage(properties);
    final Exchange exchange = mock(Exchange.class);
    when(exchange.getName()).thenReturn(testExchange);
    doReturn(exchange).when(_namedAddressSpace).getAttainedMessageDestination(eq(testExchange), anyBoolean());
    final AMQMessage convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
    final MessagePublishInfo messagePublishInfo = convertedMessage.getMessagePublishInfo();
    assertEquals("Unexpected exchange", testExchange, messagePublishInfo.getExchange().toString());
    assertEquals("Unexpected routing key", "", messagePublishInfo.getRoutingKey().toString());
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) MessagePublishInfo(org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo) Message_1_0(org.apache.qpid.server.protocol.v1_0.Message_1_0) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) Properties(org.apache.qpid.server.protocol.v1_0.type.messaging.Properties) AMQMessage(org.apache.qpid.server.protocol.v0_8.AMQMessage) Test(org.junit.Test)

Example 28 with Exchange

use of org.apache.qpid.server.model.Exchange in project qpid-broker-j by apache.

the class EmbeddedBrokerPerClassAdminImpl method createQueue.

@Override
public void createQueue(final String queueName) {
    final Map<String, Object> attributes = new HashMap<>();
    attributes.put(Queue.NAME, queueName);
    attributes.put(Queue.TYPE, "standard");
    final Queue queue = _currentVirtualHostNode.getVirtualHost().createChild(Queue.class, attributes);
    final Exchange exchange = _currentVirtualHostNode.getVirtualHost().getChildByName(Exchange.class, "amq.direct");
    exchange.bind(queueName, queueName, Collections.emptyMap(), false);
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) HashMap(java.util.HashMap) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Queue(org.apache.qpid.server.model.Queue)

Example 29 with Exchange

use of org.apache.qpid.server.model.Exchange in project qpid-broker-j by apache.

the class DirectExchangeTest method testRouteToQueueViaTwoExchangesWithReplacementRoutingKeyAndFiltering.

@Test
public void testRouteToQueueViaTwoExchangesWithReplacementRoutingKeyAndFiltering() {
    Map<String, Object> viaExchangeArguments = new HashMap<>();
    viaExchangeArguments.put(Exchange.NAME, getTestName() + "_via_exch");
    viaExchangeArguments.put(Exchange.TYPE, ExchangeDefaults.DIRECT_EXCHANGE_CLASS);
    Exchange via = _vhost.createChild(Exchange.class, viaExchangeArguments);
    Queue<?> queue = _vhost.createChild(Queue.class, Collections.singletonMap(Queue.NAME, getTestName() + "_queue"));
    Map<String, Object> exchToViaBindArguments = new HashMap<>();
    exchToViaBindArguments.put(Binding.BINDING_ARGUMENT_REPLACEMENT_ROUTING_KEY, "key2");
    exchToViaBindArguments.put(JMS_SELECTOR.toString(), "prop = True");
    boolean exchToViaBind = _exchange.bind(via.getName(), "key1", exchToViaBindArguments, false);
    assertTrue("Exchange to exchange bind operation should be successful", exchToViaBind);
    boolean viaToQueueBind = via.bind(queue.getName(), "key2", Collections.emptyMap(), false);
    assertTrue("Exchange to queue bind operation should be successful", viaToQueueBind);
    RoutingResult<ServerMessage<?>> result = _exchange.route(createTestMessage(Collections.singletonMap("prop", true)), "key1", _instanceProperties);
    assertTrue("Message unexpectedly not routed to queue", result.hasRoutes());
    result = _exchange.route(createTestMessage(Collections.singletonMap("prop", false)), "key1", _instanceProperties);
    assertFalse("Message unexpectedly routed to queue", result.hasRoutes());
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) HashMap(java.util.HashMap) ServerMessage(org.apache.qpid.server.message.ServerMessage) Test(org.junit.Test)

Example 30 with Exchange

use of org.apache.qpid.server.model.Exchange in project qpid-broker-j by apache.

the class DirectExchangeTest method testRouteToQueueViaTwoExchangesWithReplacementRoutingKey.

@Test
public void testRouteToQueueViaTwoExchangesWithReplacementRoutingKey() {
    Map<String, Object> viaExchangeArguments = new HashMap<>();
    viaExchangeArguments.put(Exchange.NAME, "via_exchange");
    viaExchangeArguments.put(Exchange.TYPE, ExchangeDefaults.DIRECT_EXCHANGE_CLASS);
    Exchange via = _vhost.createChild(Exchange.class, viaExchangeArguments);
    Queue<?> queue = _vhost.createChild(Queue.class, Collections.singletonMap(Queue.NAME, getTestName() + "_queue"));
    boolean exchToViaBind = _exchange.bind(via.getName(), "key1", Collections.singletonMap(Binding.BINDING_ARGUMENT_REPLACEMENT_ROUTING_KEY, "key2"), false);
    assertTrue("Exchange to exchange bind operation should be successful", exchToViaBind);
    boolean viaToQueueBind = via.bind(queue.getName(), "key2", Collections.emptyMap(), false);
    assertTrue("Exchange to queue bind operation should be successful", viaToQueueBind);
    RoutingResult<ServerMessage<?>> result = _exchange.route(_messageWithNoHeaders, "key1", _instanceProperties);
    assertTrue("Message unexpectedly not routed to queue", result.hasRoutes());
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) HashMap(java.util.HashMap) ServerMessage(org.apache.qpid.server.message.ServerMessage) Test(org.junit.Test)

Aggregations

Exchange (org.apache.qpid.server.model.Exchange)53 Test (org.junit.Test)29 HashMap (java.util.HashMap)24 ServerMessage (org.apache.qpid.server.message.ServerMessage)15 Queue (org.apache.qpid.server.model.Queue)15 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)14 MessageDestination (org.apache.qpid.server.message.MessageDestination)13 DestinationAddress (org.apache.qpid.server.model.DestinationAddress)8 ReplyTo (org.apache.qpid.server.protocol.v0_10.transport.ReplyTo)8 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)8 Message_1_0 (org.apache.qpid.server.protocol.v1_0.Message_1_0)8 ApplicationProperties (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)8 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)8 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)7 AccessControlException (java.security.AccessControlException)6 LinkedHashMap (java.util.LinkedHashMap)6 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)6 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)6 MessagePublishInfo (org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo)6 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)5