Java Code Examples for org.apache.qpid.proton.amqp.messaging.Source#setAddress()

The following examples show how to use org.apache.qpid.proton.amqp.messaging.Source#setAddress() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BrokerDefinedMulticastConsumerTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 60000)
public void testConsumeWhenOnlyAnycast() throws Exception {
   server.addAddressInfo(new AddressInfo(address, RoutingType.ANYCAST));

   sendMessages(address.toString(), 1);

   AmqpClient client = createAmqpClient();
   AmqpConnection connection = addConnection(client.connect());

   AmqpSession session = connection.createSession();
   Source jmsSource = createJmsSource(true);
   jmsSource.setAddress(address.toString());
   try {
      session.createReceiver(jmsSource);
      fail("should throw exception");
   } catch (Exception e) {
      //ignore
   }
   connection.close();
}
 
Example 2
Source File: BrokerDefinedAnycastConsumerTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 60000)
public void testConsumeWhenOnlyMulticast() throws Exception {
   server.addAddressInfo(new AddressInfo(address, RoutingType.MULTICAST));

   sendMessages(address.toString(), 1);

   AmqpClient client = createAmqpClient();
   AmqpConnection connection = addConnection(client.connect());

   AmqpSession session = connection.createSession();
   Source jmsSource = createJmsSource(false);
   jmsSource.setAddress(address.toString());
   try {
      session.createReceiver(jmsSource);
      fail("should throw exception");
   } catch (Exception e) {
      //ignore
   }
   connection.close();
}
 
Example 3
Source File: ProtonServerSenderContextTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test(expected = ActiveMQAMQPNotFoundException.class)
public void testAcceptsNullSourceAddressWhenInitialising() throws Exception {
   ProtonProtocolManager mock = mock(ProtonProtocolManager.class);
   when(mock.getServer()).thenReturn(mock(ActiveMQServer.class));
   Sender mockSender = mock(Sender.class);
   AMQPConnectionContext mockConnContext = mock(AMQPConnectionContext.class);
   when(mockConnContext.getProtocolManager()).thenReturn(mock);

   AMQPSessionCallback mockSessionCallback = mock(AMQPSessionCallback.class);

   AddressQueryResult queryResult = new AddressQueryResult(null, Collections.emptySet(), 0, false, false, false, false, 0);
   when(mockSessionCallback.addressQuery(any(), any(), anyBoolean())).thenReturn(queryResult);
   ProtonServerSenderContext sc = new ProtonServerSenderContext( mockConnContext, mockSender, null, mockSessionCallback);

   Source source = new Source();
   source.setAddress(null);
   when(mockSender.getRemoteSource()).thenReturn(source);


   sc.initialise();
}
 
Example 4
Source File: Pool.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public Sender newOutgoing(Session ssn, String remote, String local) {
    Sender snd = ssn.sender(String.format("%s-%s", local, remote));
    Source src = new Source();
    src.setAddress(local);
    snd.setSource(src);
    Target tgt = new Target();
    tgt.setAddress(remote);
    snd.setTarget(tgt);
    return snd;
}
 
Example 5
Source File: Pool.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public Receiver newIncoming(Session ssn, String remote, String local) {
    Receiver rcv = ssn.receiver(String.format("%s-%s", remote, local));
    Source src = new Source();
    src.setAddress(remote);
    rcv.setSource(src);
    Target tgt = new Target();
    tgt.setAddress(remote);
    rcv.setTarget(tgt);
    return rcv;
}
 
Example 6
Source File: AmqpReceiverTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 60000)
public void testClientIdIsSetInSubscriptionList() throws Exception {
   server.addAddressInfo(new AddressInfo(SimpleString.toSimpleString("mytopic"), RoutingType.ANYCAST));

   AmqpClient client = createAmqpClient();
   AmqpConnection connection = addConnection(client.connect());
   connection.setContainerId("testClient");
   connection.connect();

   try {
      AmqpSession session = connection.createSession();

      Source source = new Source();
      source.setDurable(TerminusDurability.UNSETTLED_STATE);
      source.setCapabilities(Symbol.getSymbol("topic"));
      source.setAddress("mytopic");
      session.createReceiver(source, "testSub");

      SimpleString fo = new SimpleString("testClient.testSub:mytopic");
      assertNotNull(server.locateQueue(fo));

   } catch (Exception e) {
      e.printStackTrace();
   } finally {
      connection.close();
   }
}
 
Example 7
Source File: ClientDefinedMultiConsumerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private Source createNonSharedSource(TerminusDurability terminusDurability) {
   Source source = new Source();
   source.setAddress(address.toString());
   source.setCapabilities(TOPIC_CAPABILITY);
   source.setDurable(terminusDurability);
   return source;
}
 
Example 8
Source File: ClientDefinedMultiConsumerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private Source createSharedSource(TerminusDurability terminusDurability) {
   Source source = new Source();
   source.setAddress(address.toString());
   source.setCapabilities(TOPIC_CAPABILITY, SHARED);
   source.setDurable(terminusDurability);
   return source;
}
 
Example 9
Source File: ClientDefinedMultiConsumerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private Source createSharedGlobalSource(TerminusDurability terminusDurability) {
   Source source = new Source();
   source.setAddress(address.toString());
   source.setCapabilities(TOPIC_CAPABILITY, SHARED, GLOBAL);
   source.setDurable(terminusDurability);
   return source;
}
 
Example 10
Source File: ProtonSessionImpl.java    From vertx-proton with Apache License 2.0 5 votes vote down vote up
@Override
public ProtonReceiver createReceiver(String address, ProtonLinkOptions receiverOptions) {
  Receiver receiver = session.receiver(getOrCreateLinkName(receiverOptions));

  Symbol[] outcomes = new Symbol[] { Accepted.DESCRIPTOR_SYMBOL, Rejected.DESCRIPTOR_SYMBOL,
      Released.DESCRIPTOR_SYMBOL, Modified.DESCRIPTOR_SYMBOL };

  Source source = new Source();
  source.setAddress(address);
  source.setOutcomes(outcomes);
  source.setDefaultOutcome(Released.getInstance());
  if(receiverOptions.isDynamic()) {
    source.setDynamic(true);
  }

  Target target = new Target();

  receiver.setSource(source);
  receiver.setTarget(target);

  ProtonReceiverImpl r = new ProtonReceiverImpl(receiver);
  r.openHandler((result) -> {
    LOG.trace("Receiver open completed");
  });
  r.closeHandler((result) -> {
    if (result.succeeded()) {
      LOG.trace("Receiver closed");
    } else {
      LOG.warn("Receiver closed with error", result.cause());
    }
  });

  // Default to at-least-once
  r.setQoS(ProtonQoS.AT_LEAST_ONCE);

  return r;
}
 
Example 11
Source File: AmqpProducerBuilder.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Override
protected Sender createEndpoint(JmsProducerInfo resourceInfo) {
    JmsDestination destination = resourceInfo.getDestination();
    AmqpConnection connection = getParent().getConnection();

    String targetAddress = AmqpDestinationHelper.getDestinationAddress(destination, connection);

    Symbol[] outcomes = new Symbol[]{ Accepted.DESCRIPTOR_SYMBOL, Rejected.DESCRIPTOR_SYMBOL, Released.DESCRIPTOR_SYMBOL, Modified.DESCRIPTOR_SYMBOL };
    String sourceAddress = resourceInfo.getId().toString();
    Source source = new Source();
    source.setAddress(sourceAddress);
    source.setOutcomes(outcomes);
    // TODO: default outcome. Accepted normally, Rejected for transaction controller?

    Target target = new Target();
    target.setAddress(targetAddress);
    Symbol typeCapability =  AmqpDestinationHelper.toTypeCapability(destination);
    if (typeCapability != null) {
        target.setCapabilities(typeCapability);
    }

    String senderName = "qpid-jms:sender:" + sourceAddress + ":" + targetAddress;

    Sender sender = getParent().getEndpoint().sender(senderName);
    sender.setSource(source);
    sender.setTarget(target);
    if (resourceInfo.isPresettle()) {
        sender.setSenderSettleMode(SenderSettleMode.SETTLED);
    } else {
        sender.setSenderSettleMode(SenderSettleMode.UNSETTLED);
    }
    sender.setReceiverSettleMode(ReceiverSettleMode.FIRST);

    if (!connection.getProperties().isDelayedDeliverySupported()) {
        validateDelayedDeliveryLinkCapability = true;
        sender.setDesiredCapabilities(new Symbol[] { AmqpSupport.DELAYED_DELIVERY });
    }

    return sender;
}
 
Example 12
Source File: QueueTerminusFactory.java    From enmasse with Apache License 2.0 4 votes vote down vote up
@Override
public Source getSource(String address) {
    Source source = new Source();
    source.setAddress(address);
    return source;
}
 
Example 13
Source File: MessagingAddressTest.java    From enmasse with Apache License 2.0 4 votes vote down vote up
@Test
public void testDeadLetterConsume() throws Exception {
    MessagingEndpoint ingress = new MessagingEndpointBuilder()
            .editOrNewMetadata()
            .withName("dlq")
            .withNamespace(tenant.getMetadata().getNamespace())
            .endMetadata()
            .editOrNewSpec()
            .editOrNewNodePort()
            .endNodePort()
            .withHost(kubernetes.getHost())
            .addToProtocols("AMQP")
            .endSpec()
            .build();
    resourceManager.createResource(ingress);
    resourceManager.createResource(new MessagingAddressBuilder()
            .editOrNewMetadata()
            .withName("dlq1")
            .withNamespace(tenant.getMetadata().getNamespace())
            .endMetadata()
            .editOrNewSpec()
            .editOrNewDeadLetter()
            .endDeadLetter()
            .endSpec()
            .build());
    resourceManager.createResource(new MessagingAddressBuilder()
            .editOrNewMetadata()
            .withName("queue1")
            .withNamespace(tenant.getMetadata().getNamespace())
            .endMetadata()
            .editOrNewSpec()
            .editOrNewQueue()
            .withDeadLetterAddress("dlq1")
            .endQueue()
            .endSpec()
            .build());


    AmqpClient client = resourceManager.getAmqpClientFactory().createClient(new AmqpConnectOptions()
            .setSaslMechanism("ANONYMOUS")
            .setQos(ProtonQoS.AT_LEAST_ONCE)
            .setEndpoint(new Endpoint(ingress.getStatus().getHost(), ingress.getStatus().getPorts().get(0).getPort()))
            .setProtonClientOptions(new ProtonClientOptions())
            .setTerminusFactory(new QueueTerminusFactory()));

    assertEquals(1, client.sendMessages("queue1", Collections.singletonList("todeadletter")).get(1, TimeUnit.MINUTES));
    Source source = new Source();
    source.setAddress("queue1");
    AtomicInteger redeliveries = new AtomicInteger(0);
    assertEquals(1, client.recvMessages(source, message -> redeliveries.incrementAndGet() >= 1, Optional.empty(), protonDelivery -> protonDelivery.disposition(new Rejected(), true)).getResult().get(1, TimeUnit.MINUTES).size());
    assertEquals(1, client.recvMessages("dlq1", 1).get(1, TimeUnit.MINUTES).size());
}
 
Example 14
Source File: SourceType.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
public Source newInstance(Object described)
{
    List l = (List) described;

    Source o = new Source();


    switch(11 - l.size())
    {

        case 0:
            Object val0 = l.get( 10 );
            if( val0 == null || val0.getClass().isArray() )
            {
                o.setCapabilities( (Symbol[]) val0 );
            }
            else
            {
                o.setCapabilities( (Symbol) val0 );
            }
        case 1:
            Object val1 = l.get( 9 );
            if( val1 == null || val1.getClass().isArray() )
            {
                o.setOutcomes( (Symbol[]) val1 );
            }
            else
            {
                o.setOutcomes( (Symbol) val1 );
            }
        case 2:
            o.setDefaultOutcome( (Outcome) l.get( 8 ) );
        case 3:
            o.setFilter( (Map) l.get( 7 ) );
        case 4:
            o.setDistributionMode( (Symbol) l.get( 6 ) );
        case 5:
            o.setDynamicNodeProperties( (Map) l.get( 5 ) );
        case 6:
            Boolean dynamic = (Boolean) l.get(4);
            o.setDynamic(dynamic == null ? false : dynamic);
        case 7:
            UnsignedInteger timeout = (UnsignedInteger) l.get(3);
            o.setTimeout(timeout == null ? UnsignedInteger.ZERO : timeout);
        case 8:
            Symbol expiryPolicy = (Symbol) l.get(2);
            o.setExpiryPolicy(expiryPolicy == null ? TerminusExpiryPolicy.SESSION_END : TerminusExpiryPolicy.valueOf(expiryPolicy));
        case 9:
            UnsignedInteger durable = (UnsignedInteger) l.get(1);
            o.setDurable(durable == null ? TerminusDurability.NONE : TerminusDurability.get(durable));
        case 10:
            o.setAddress( (String) l.get( 0 ) );
    }


    return o;
}
 
Example 15
Source File: LinkTest.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Test
public void testMaxMessageSizeValue() throws Exception
{
    LOGGER.fine(bold("======== About to create transports"));

    Transport clientTransport = Proton.transport();
    getClient().setTransport(clientTransport);
    ProtocolTracerEnabler.setProtocolTracer(clientTransport, TestLoggingHelper.CLIENT_PREFIX);

    Transport serverTransport = Proton.transport();
    getServer().setTransport(serverTransport);
    ProtocolTracerEnabler.setProtocolTracer(serverTransport, "            " + TestLoggingHelper.SERVER_PREFIX);

    doOutputInputCycle();

    Connection clientConnection = Proton.connection();
    getClient().setConnection(clientConnection);
    clientTransport.bind(clientConnection);

    Connection serverConnection = Proton.connection();
    getServer().setConnection(serverConnection);
    serverTransport.bind(serverConnection);

    LOGGER.fine(bold("======== About to open connections"));
    clientConnection.open();
    serverConnection.open();

    doOutputInputCycle();

    LOGGER.fine(bold("======== About to open sessions"));
    Session clientSession = clientConnection.session();
    getClient().setSession(clientSession);
    clientSession.open();

    pumpClientToServer();

    Session serverSession = serverConnection.sessionHead(of(UNINITIALIZED), of(ACTIVE));
    getServer().setSession(serverSession);

    serverSession.open();

    pumpServerToClient();

    LOGGER.fine(bold("======== About to create receiver"));

    Source clientSource = new Source();
    getClient().setSource(clientSource);
    clientSource.setAddress(_sourceAddress);

    Target clientTarget = new Target();
    getClient().setTarget(clientTarget);
    clientTarget.setAddress(null);

    Receiver clientReceiver = clientSession.receiver("link1");
    getClient().setReceiver(clientReceiver);
    clientReceiver.setTarget(clientTarget);
    clientReceiver.setSource(clientSource);

    clientReceiver.setReceiverSettleMode(ReceiverSettleMode.FIRST);
    clientReceiver.setSenderSettleMode(SenderSettleMode.UNSETTLED);

    // Set the local link max-message-size
    assertNull("Expected no value to be set", clientReceiver.getMaxMessageSize());
    clientReceiver.setMaxMessageSize(CLIENT_MAX_MSG_SIZE);
    assertEquals("Expected value to be set", CLIENT_MAX_MSG_SIZE, clientReceiver.getMaxMessageSize());

    clientReceiver.open();
    pumpClientToServer();

    LOGGER.fine(bold("======== About to set up implicitly created sender"));

    Sender serverSender = (Sender) getServer().getConnection().linkHead(of(UNINITIALIZED), of(ACTIVE));
    getServer().setSender(serverSender);

    serverSender.setReceiverSettleMode(serverSender.getRemoteReceiverSettleMode());
    serverSender.setSenderSettleMode(serverSender.getRemoteSenderSettleMode());

    org.apache.qpid.proton.amqp.transport.Source serverRemoteSource = serverSender.getRemoteSource();
    serverSender.setSource(serverRemoteSource);

    assertEquals("Expected value to be set", CLIENT_MAX_MSG_SIZE, serverSender.getRemoteMaxMessageSize());

    // Set the local link max-message-size
    assertNull("Expected no value to be set", serverSender.getMaxMessageSize());
    serverSender.setMaxMessageSize(SERVER_MAX_MSG_SIZE);
    assertEquals("Expected value to be set", SERVER_MAX_MSG_SIZE, serverSender.getMaxMessageSize());

    serverSender.open();

    assertNull("Expected no value to be present yet", clientReceiver.getRemoteMaxMessageSize());

    pumpServerToClient();

    assertEquals("Expected value to be set", SERVER_MAX_MSG_SIZE, clientReceiver.getRemoteMaxMessageSize());
}
 
Example 16
Source File: AmqpConsumerBuilder.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
@Override
protected Receiver createEndpoint(JmsConsumerInfo resourceInfo) {
    JmsDestination destination = resourceInfo.getDestination();
    String address = AmqpDestinationHelper.getDestinationAddress(destination, getParent().getConnection());

    Source source = new Source();
    source.setAddress(address);
    Target target = new Target();

    configureSource(source);

    String receiverLinkName = null;
    String subscriptionName = resourceInfo.getSubscriptionName();
    if (subscriptionName != null && !subscriptionName.isEmpty()) {
        AmqpConnection connection = getParent().getConnection();

        if (resourceInfo.isShared() && !connection.getProperties().isSharedSubsSupported()) {
            validateSharedSubsLinkCapability = true;
        }

        AmqpSubscriptionTracker subTracker = connection.getSubTracker();

        // Validate subscriber type allowed given existing active subscriber types.
        if (resourceInfo.isShared() && resourceInfo.isDurable()) {
            if(subTracker.isActiveExclusiveDurableSub(subscriptionName)) {
                // Don't allow shared sub if there is already an active exclusive durable sub
                throw new JMSRuntimeException("A non-shared durable subscription is already active with name '" + subscriptionName + "'");
            }
        } else if (!resourceInfo.isShared() && resourceInfo.isDurable()) {
            if (subTracker.isActiveExclusiveDurableSub(subscriptionName)) {
                // Exclusive durable sub is already active
                throw new JMSRuntimeException("A non-shared durable subscription is already active with name '" + subscriptionName + "'");
            } else if (subTracker.isActiveSharedDurableSub(subscriptionName)) {
                // Don't allow exclusive durable sub if there is already an active shared durable sub
                throw new JMSRuntimeException("A shared durable subscription is already active with name '" + subscriptionName + "'");
            }
        }

        // Get the link name for the subscription. Throws if certain further validations fail.
        receiverLinkName = subTracker.reserveNextSubscriptionLinkName(subscriptionName, resourceInfo);
    }

    if (receiverLinkName == null) {
        receiverLinkName = "qpid-jms:receiver:" + resourceInfo.getId() + ":" + address;
    }

    Receiver receiver = getParent().getEndpoint().receiver(receiverLinkName);
    receiver.setSource(source);
    receiver.setTarget(target);
    if (resourceInfo.isBrowser() || resourceInfo.isPresettle()) {
        receiver.setSenderSettleMode(SenderSettleMode.SETTLED);
    } else {
        receiver.setSenderSettleMode(SenderSettleMode.UNSETTLED);
    }
    receiver.setReceiverSettleMode(ReceiverSettleMode.FIRST);

    if (validateSharedSubsLinkCapability) {
        receiver.setDesiredCapabilities(new Symbol[] { AmqpSupport.SHARED_SUBS });
    }

    return receiver;
}