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;
}
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);
}
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);
}
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);
}
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.");
}
}
}
Aggregations