io.vertx.rxjava.amqp.AmqpClient Maven / Gradle / Ivy
/*
* Copyright 2014 Red Hat, Inc.
*
* Red Hat licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.vertx.rxjava.amqp;
import rx.Observable;
import rx.Single;
import io.vertx.rx.java.RxHelper;
import io.vertx.rx.java.WriteStreamSubscriber;
import io.vertx.rx.java.SingleOnSubscribeAdapter;
import java.util.Map;
import java.util.Set;
import java.util.List;
import java.util.Iterator;
import java.util.function.Function;
import java.util.stream.Collectors;
import io.vertx.core.Handler;
import io.vertx.core.AsyncResult;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;
import io.vertx.lang.rx.RxGen;
import io.vertx.lang.rx.TypeArg;
import io.vertx.lang.rx.MappingIterator;
/**
* AMQP Client entry point.
* Use this interface to create an instance of {@link io.vertx.rxjava.amqp.AmqpClient} and connect to a broker and server.
*
*
* NOTE: This class has been automatically generated from the {@link io.vertx.amqp.AmqpClient original} non RX-ified interface using Vert.x codegen.
*/
@RxGen(io.vertx.amqp.AmqpClient.class)
public class AmqpClient {
@Override
public String toString() {
return delegate.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AmqpClient that = (AmqpClient) o;
return delegate.equals(that.delegate);
}
@Override
public int hashCode() {
return delegate.hashCode();
}
public static final TypeArg __TYPE_ARG = new TypeArg<>( obj -> new AmqpClient((io.vertx.amqp.AmqpClient) obj),
AmqpClient::getDelegate
);
private final io.vertx.amqp.AmqpClient delegate;
public AmqpClient(io.vertx.amqp.AmqpClient delegate) {
this.delegate = delegate;
}
public AmqpClient(Object delegate) {
this.delegate = (io.vertx.amqp.AmqpClient)delegate;
}
public io.vertx.amqp.AmqpClient getDelegate() {
return delegate;
}
/**
* Creates a new instance of {@link io.vertx.rxjava.amqp.AmqpClient} using an internal Vert.x instance (with default configuration) and
* the given AMQP client configuration. Note that the created Vert.x instance will be closed when the client is
* closed.
* @param options the AMQP client options, may be null
falling back to the default configuration
* @return the created instances.
*/
public static io.vertx.rxjava.amqp.AmqpClient create(io.vertx.amqp.AmqpClientOptions options) {
io.vertx.rxjava.amqp.AmqpClient ret = io.vertx.rxjava.amqp.AmqpClient.newInstance((io.vertx.amqp.AmqpClient)io.vertx.amqp.AmqpClient.create(options));
return ret;
}
/**
* Creates a new instance of {@link io.vertx.rxjava.amqp.AmqpClient} with the given Vert.x instance and the given options.
* @param vertx the vert.x instance, must not be null
* @param options the AMQP options, may be @{code null} falling back to the default configuration
* @return the AMQP client instance
*/
public static io.vertx.rxjava.amqp.AmqpClient create(io.vertx.rxjava.core.Vertx vertx, io.vertx.amqp.AmqpClientOptions options) {
io.vertx.rxjava.amqp.AmqpClient ret = io.vertx.rxjava.amqp.AmqpClient.newInstance((io.vertx.amqp.AmqpClient)io.vertx.amqp.AmqpClient.create(vertx.getDelegate(), options));
return ret;
}
/**
* Connects to the AMQP broker or router. The location is specified in the {@link io.vertx.amqp.AmqpClientOptions} as well as the
* potential credential required.
* @param connectionHandler handler that will process the result, giving either the connection or failure cause. Must not be null
.
* @return
*/
public io.vertx.rxjava.amqp.AmqpClient connect(Handler> connectionHandler) {
delegate.connect(new Handler>() {
public void handle(AsyncResult ar) {
if (ar.succeeded()) {
connectionHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.amqp.AmqpConnection.newInstance((io.vertx.amqp.AmqpConnection)ar.result())));
} else {
connectionHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
return this;
}
/**
* Connects to the AMQP broker or router. The location is specified in the {@link io.vertx.amqp.AmqpClientOptions} as well as the
* potential credential required.
* @return
*/
public io.vertx.rxjava.amqp.AmqpClient connect() {
return
connect(ar -> { });
}
/**
* Connects to the AMQP broker or router. The location is specified in the {@link io.vertx.amqp.AmqpClientOptions} as well as the
* potential credential required.
* @return
*/
public Single rxConnect() {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
connect(fut);
}));
}
/**
* Closes the client.
* The client must always be closed once not needed anymore.
* @param closeHandler the close handler notified when the operation completes. It can be null
.
*/
public void close(Handler> closeHandler) {
delegate.close(closeHandler);
}
/**
* Closes the client.
* The client must always be closed once not needed anymore.
*/
public void close() {
close(ar -> { });
}
/**
* Closes the client.
* The client must always be closed once not needed anymore.
* @return
*/
public Single rxClose() {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
close(fut);
}));
}
/**
* Creates a receiver used to consume messages from the given address. The receiver has no handler and won't
* start receiving messages until a handler is explicitly configured. This method avoids having to connect explicitly.
* You can retrieve the connection using {@link io.vertx.rxjava.amqp.AmqpReceiver#connection}.
* @param address The source address to attach the consumer to, must not be null
* @param completionHandler the handler called with the receiver. The receiver has been opened.
* @return the client.
*/
public io.vertx.rxjava.amqp.AmqpClient createReceiver(String address, Handler> completionHandler) {
delegate.createReceiver(address, new Handler>() {
public void handle(AsyncResult ar) {
if (ar.succeeded()) {
completionHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.amqp.AmqpReceiver.newInstance((io.vertx.amqp.AmqpReceiver)ar.result())));
} else {
completionHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
return this;
}
/**
* Creates a receiver used to consume messages from the given address. The receiver has no handler and won't
* start receiving messages until a handler is explicitly configured. This method avoids having to connect explicitly.
* You can retrieve the connection using {@link io.vertx.rxjava.amqp.AmqpReceiver#connection}.
* @param address The source address to attach the consumer to, must not be null
* @return the client.
*/
public io.vertx.rxjava.amqp.AmqpClient createReceiver(String address) {
return
createReceiver(address, ar -> { });
}
/**
* Creates a receiver used to consume messages from the given address. The receiver has no handler and won't
* start receiving messages until a handler is explicitly configured. This method avoids having to connect explicitly.
* You can retrieve the connection using {@link io.vertx.rxjava.amqp.AmqpReceiver#connection}.
* @param address The source address to attach the consumer to, must not be null
* @return the client.
*/
public Single rxCreateReceiver(String address) {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
createReceiver(address, fut);
}));
}
/**
* Creates a receiver used to consumer messages from the given address. This method avoids having to connect
* explicitly. You can retrieve the connection using {@link io.vertx.rxjava.amqp.AmqpReceiver#connection}.
* @param address The source address to attach the consumer to.
* @param receiverOptions The options for this receiver.
* @param completionHandler The handler called with the receiver, once opened. Note that the messageHandler
can be called before the completionHandler
if messages are awaiting delivery.
* @return the connection.
*/
public io.vertx.rxjava.amqp.AmqpClient createReceiver(String address, io.vertx.amqp.AmqpReceiverOptions receiverOptions, Handler> completionHandler) {
delegate.createReceiver(address, receiverOptions, new Handler>() {
public void handle(AsyncResult ar) {
if (ar.succeeded()) {
completionHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.amqp.AmqpReceiver.newInstance((io.vertx.amqp.AmqpReceiver)ar.result())));
} else {
completionHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
return this;
}
/**
* Creates a receiver used to consumer messages from the given address. This method avoids having to connect
* explicitly. You can retrieve the connection using {@link io.vertx.rxjava.amqp.AmqpReceiver#connection}.
* @param address The source address to attach the consumer to.
* @param receiverOptions The options for this receiver.
* @return the connection.
*/
public io.vertx.rxjava.amqp.AmqpClient createReceiver(String address, io.vertx.amqp.AmqpReceiverOptions receiverOptions) {
return
createReceiver(address, receiverOptions, ar -> { });
}
/**
* Creates a receiver used to consumer messages from the given address. This method avoids having to connect
* explicitly. You can retrieve the connection using {@link io.vertx.rxjava.amqp.AmqpReceiver#connection}.
* @param address The source address to attach the consumer to.
* @param receiverOptions The options for this receiver.
* @return the connection.
*/
public Single rxCreateReceiver(String address, io.vertx.amqp.AmqpReceiverOptions receiverOptions) {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
createReceiver(address, receiverOptions, fut);
}));
}
/**
* Creates a sender used to send messages to the given address. The address must be set.
* @param address The target address to attach to, must not be null
* @param completionHandler The handler called with the sender, once opened
* @return the client.
*/
public io.vertx.rxjava.amqp.AmqpClient createSender(String address, Handler> completionHandler) {
delegate.createSender(address, new Handler>() {
public void handle(AsyncResult ar) {
if (ar.succeeded()) {
completionHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.amqp.AmqpSender.newInstance((io.vertx.amqp.AmqpSender)ar.result())));
} else {
completionHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
return this;
}
/**
* Creates a sender used to send messages to the given address. The address must be set.
* @param address The target address to attach to, must not be null
* @return the client.
*/
public io.vertx.rxjava.amqp.AmqpClient createSender(String address) {
return
createSender(address, ar -> { });
}
/**
* Creates a sender used to send messages to the given address. The address must be set.
* @param address The target address to attach to, must not be null
* @return the client.
*/
public Single rxCreateSender(String address) {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
createSender(address, fut);
}));
}
/**
* Creates a sender used to send messages to the given address. The address must be set.
* @param address The target address to attach to, must not be null
* @param options The options for this sender.
* @param completionHandler The handler called with the sender, once opened
* @return the client.
*/
public io.vertx.rxjava.amqp.AmqpClient createSender(String address, io.vertx.amqp.AmqpSenderOptions options, Handler> completionHandler) {
delegate.createSender(address, options, new Handler>() {
public void handle(AsyncResult ar) {
if (ar.succeeded()) {
completionHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.amqp.AmqpSender.newInstance((io.vertx.amqp.AmqpSender)ar.result())));
} else {
completionHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
return this;
}
/**
* Creates a sender used to send messages to the given address. The address must be set.
* @param address The target address to attach to, must not be null
* @param options The options for this sender.
* @return the client.
*/
public io.vertx.rxjava.amqp.AmqpClient createSender(String address, io.vertx.amqp.AmqpSenderOptions options) {
return
createSender(address, options, ar -> { });
}
/**
* Creates a sender used to send messages to the given address. The address must be set.
* @param address The target address to attach to, must not be null
* @param options The options for this sender.
* @return the client.
*/
public Single rxCreateSender(String address, io.vertx.amqp.AmqpSenderOptions options) {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
createSender(address, options, fut);
}));
}
public static AmqpClient newInstance(io.vertx.amqp.AmqpClient arg) {
return arg != null ? new AmqpClient(arg) : null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy