Search in sources :

Example 1 with Sender

use of org.apache.qpid.protonj2.client.Sender in project qpid-protonj2 by apache.

the class ClientSenderBuilder method getDefaultSenderOptions.

/*
     * Sender options used when none specified by the caller creating a new sender.
     */
private SenderOptions getDefaultSenderOptions() {
    SenderOptions senderOptions = defaultSenderOptions;
    if (senderOptions == null) {
        synchronized (this) {
            senderOptions = defaultSenderOptions;
            if (senderOptions == null) {
                senderOptions = new SenderOptions();
                senderOptions.openTimeout(sessionOptions.openTimeout());
                senderOptions.closeTimeout(sessionOptions.closeTimeout());
                senderOptions.requestTimeout(sessionOptions.requestTimeout());
                senderOptions.sendTimeout(sessionOptions.sendTimeout());
            }
            defaultSenderOptions = senderOptions;
        }
    }
    return senderOptions;
}
Also used : SenderOptions(org.apache.qpid.protonj2.client.SenderOptions) StreamSenderOptions(org.apache.qpid.protonj2.client.StreamSenderOptions)

Example 2 with Sender

use of org.apache.qpid.protonj2.client.Sender in project qpid-protonj2 by apache.

the class ClientSenderBuilder method anonymousSender.

public ClientSender anonymousSender(SenderOptions senderOptions) throws ClientException {
    final SenderOptions options = senderOptions != null ? senderOptions : getDefaultSenderOptions();
    final String senderId = nextSenderId();
    final Sender protonSender = createSender(session.getProtonSession(), null, options, senderId);
    return new ClientSender(session, options, senderId, protonSender);
}
Also used : Sender(org.apache.qpid.protonj2.engine.Sender) SenderOptions(org.apache.qpid.protonj2.client.SenderOptions) StreamSenderOptions(org.apache.qpid.protonj2.client.StreamSenderOptions)

Example 3 with Sender

use of org.apache.qpid.protonj2.client.Sender in project qpid-protonj2 by apache.

the class ClientSenderBuilder method streamSender.

public ClientStreamSender streamSender(String address, StreamSenderOptions senderOptions) throws ClientException {
    final StreamSenderOptions options = senderOptions != null ? senderOptions : getDefaultStreamSenderOptions();
    final String senderId = nextSenderId();
    final Sender protonSender = createSender(session.getProtonSession(), address, options, senderId);
    return new ClientStreamSender(session, options, senderId, protonSender);
}
Also used : Sender(org.apache.qpid.protonj2.engine.Sender) StreamSenderOptions(org.apache.qpid.protonj2.client.StreamSenderOptions)

Example 4 with Sender

use of org.apache.qpid.protonj2.client.Sender in project qpid-protonj2 by apache.

the class ClientSenderBuilder method sender.

public ClientSender sender(String address, SenderOptions senderOptions) throws ClientException {
    final SenderOptions options = senderOptions != null ? senderOptions : getDefaultSenderOptions();
    final String senderId = nextSenderId();
    final Sender protonSender = createSender(session.getProtonSession(), address, options, senderId);
    return new ClientSender(session, options, senderId, protonSender);
}
Also used : Sender(org.apache.qpid.protonj2.engine.Sender) SenderOptions(org.apache.qpid.protonj2.client.SenderOptions) StreamSenderOptions(org.apache.qpid.protonj2.client.StreamSenderOptions)

Example 5 with Sender

use of org.apache.qpid.protonj2.client.Sender in project qpid-protonj2 by apache.

the class Respond method main.

public static void main(String[] args) throws Exception {
    final String serverHost = System.getProperty("HOST", "localhost");
    final int serverPort = Integer.getInteger("PORT", 5672);
    final String address = System.getProperty("ADDRESS", "request-respond-example");
    final Client client = Client.create();
    final ConnectionOptions options = new ConnectionOptions();
    options.user(System.getProperty("USER"));
    options.password(System.getProperty("PASSWORD"));
    try (Connection connection = client.connect(serverHost, serverPort, options)) {
        ReceiverOptions receiverOptions = new ReceiverOptions();
        receiverOptions.sourceOptions().capabilities("queue");
        Receiver receiver = connection.openReceiver(address, receiverOptions);
        Delivery request = receiver.receive(60, TimeUnit.SECONDS);
        if (request != null) {
            Message<String> received = request.message();
            System.out.println("Received message with body: " + received.body());
            String replyAddress = received.replyTo();
            if (replyAddress != null) {
                Sender sender = connection.openSender(replyAddress);
                sender.send(Message.create("Response"));
            }
        } else {
            System.out.println("Failed to read a message during the defined wait interval.");
        }
    }
}
Also used : Sender(org.apache.qpid.protonj2.client.Sender) Connection(org.apache.qpid.protonj2.client.Connection) ReceiverOptions(org.apache.qpid.protonj2.client.ReceiverOptions) Receiver(org.apache.qpid.protonj2.client.Receiver) ConnectionOptions(org.apache.qpid.protonj2.client.ConnectionOptions) Delivery(org.apache.qpid.protonj2.client.Delivery) Client(org.apache.qpid.protonj2.client.Client)

Aggregations

Test (org.junit.jupiter.api.Test)176 Client (org.apache.qpid.protonj2.client.Client)145 Connection (org.apache.qpid.protonj2.client.Connection)145 URI (java.net.URI)136 ProtonTestServer (org.apache.qpid.protonj2.test.driver.ProtonTestServer)134 Connection (org.apache.qpid.protonj2.engine.Connection)96 Engine (org.apache.qpid.protonj2.engine.Engine)96 ProtonTestConnector (org.apache.qpid.protonj2.test.driver.ProtonTestConnector)96 Sender (org.apache.qpid.protonj2.engine.Sender)95 Session (org.apache.qpid.protonj2.engine.Session)94 Sender (org.apache.qpid.protonj2.client.Sender)88 Session (org.apache.qpid.protonj2.client.Session)72 OutgoingDelivery (org.apache.qpid.protonj2.engine.OutgoingDelivery)51 StreamSender (org.apache.qpid.protonj2.client.StreamSender)50 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)49 TransferPayloadCompositeMatcher (org.apache.qpid.protonj2.test.driver.matchers.transport.TransferPayloadCompositeMatcher)44 Tracker (org.apache.qpid.protonj2.client.Tracker)40 StreamSenderMessage (org.apache.qpid.protonj2.client.StreamSenderMessage)38 ConnectionOptions (org.apache.qpid.protonj2.client.ConnectionOptions)33 SenderOptions (org.apache.qpid.protonj2.client.SenderOptions)33