All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.vertx.reactivex.rabbitmq.RabbitMQPublisher 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.reactivex.rabbitmq;

import io.vertx.reactivex.RxHelper;
import io.vertx.reactivex.ObservableHelper;
import io.vertx.reactivex.FlowableHelper;
import io.vertx.reactivex.impl.AsyncResultMaybe;
import io.vertx.reactivex.impl.AsyncResultSingle;
import io.vertx.reactivex.impl.AsyncResultCompletable;
import io.vertx.reactivex.WriteStreamObserver;
import io.vertx.reactivex.WriteStreamSubscriber;
import java.util.Map;
import java.util.Set;
import java.util.List;
import java.util.Iterator;
import java.util.function.Function;
import java.util.function.Supplier;
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;

/**
 * A reliable publisher that
 * 
    *
  • Queues up messages internally until it can successfully call basicPublish. *
  • Notifies the caller using a robust ID (not delivery tag) when the message is confirmed by rabbit. *
* * This is a layer above the RabbitMQClient that provides a lot of standard implementation when guaranteed at least once delivery is required. * If confirmations are not required do not use this publisher as it does have overhead. * *

* NOTE: This class has been automatically generated from the {@link io.vertx.rabbitmq.RabbitMQPublisher original} non RX-ified interface using Vert.x codegen. */ @RxGen(io.vertx.rabbitmq.RabbitMQPublisher.class) public class RabbitMQPublisher { @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; RabbitMQPublisher that = (RabbitMQPublisher) o; return delegate.equals(that.delegate); } @Override public int hashCode() { return delegate.hashCode(); } public static final TypeArg __TYPE_ARG = new TypeArg<>( obj -> new RabbitMQPublisher((io.vertx.rabbitmq.RabbitMQPublisher) obj), RabbitMQPublisher::getDelegate ); private final io.vertx.rabbitmq.RabbitMQPublisher delegate; public RabbitMQPublisher(io.vertx.rabbitmq.RabbitMQPublisher delegate) { this.delegate = delegate; } public RabbitMQPublisher(Object delegate) { this.delegate = (io.vertx.rabbitmq.RabbitMQPublisher)delegate; } public io.vertx.rabbitmq.RabbitMQPublisher getDelegate() { return delegate; } /** * Create and return a publisher using the specified client. * @param vertx the vertx instance. * @param client the RabbitMQClient. * @param options options for the publisher. * @return the publisher */ public static io.vertx.reactivex.rabbitmq.RabbitMQPublisher create(io.vertx.reactivex.core.Vertx vertx, io.vertx.reactivex.rabbitmq.RabbitMQClient client, io.vertx.rabbitmq.RabbitMQPublisherOptions options) { io.vertx.reactivex.rabbitmq.RabbitMQPublisher ret = io.vertx.reactivex.rabbitmq.RabbitMQPublisher.newInstance((io.vertx.rabbitmq.RabbitMQPublisher)io.vertx.rabbitmq.RabbitMQPublisher.create(vertx.getDelegate(), client.getDelegate(), options)); return ret; } /** * Start the rabbitMQ publisher. * The RabbitMQClient should have been started before this. * * @return */ public io.vertx.core.Future start() { io.vertx.core.Future ret = delegate.start().map(val -> val); return ret; } /** * Start the rabbitMQ publisher. * The RabbitMQClient should have been started before this. * * @return */ public io.reactivex.Completable rxStart() { return AsyncResultCompletable.toCompletable($handler -> { this.start().onComplete($handler); }); } /** * Stop the rabbitMQ publisher. * Calling this is optional, but it gives the opportunity to drain the send queue without losing messages. * Future calls to publish will be ignored. * * @return */ public io.vertx.core.Future stop() { io.vertx.core.Future ret = delegate.stop().map(val -> val); return ret; } /** * Stop the rabbitMQ publisher. * Calling this is optional, but it gives the opportunity to drain the send queue without losing messages. * Future calls to publish will be ignored. * * @return */ public io.reactivex.Completable rxStop() { return AsyncResultCompletable.toCompletable($handler -> { this.stop().onComplete($handler); }); } /** * Undo the effects of calling so that publish may be called again. * It is harmless to call restart() when has not been called, however if restart() is called * whilst is being processed the will never complete. * */ public void restart() { delegate.restart(); } /** * Get the ReadStream that contains the message IDs for confirmed messages. * The message IDs in this ReadStream are taken from the message properties, * if these message IDs are not set then this ReadStream will contain nulls and using this publisher will be pointless. * @return the ReadStream that contains the message IDs for confirmed messages. */ public io.vertx.reactivex.core.streams.ReadStream getConfirmationStream() { io.vertx.reactivex.core.streams.ReadStream ret = io.vertx.reactivex.core.streams.ReadStream.newInstance((io.vertx.core.streams.ReadStream)delegate.getConfirmationStream(), TypeArg.unknown()); return ret; } /** * Get the number of published, but not sent, messages. * @return the number of published, but not sent, messages. */ public int queueSize() { int ret = delegate.queueSize(); return ret; } /** * Publish a message. * @param exchange * @param routingKey * @param properties * @param body * @return */ public io.vertx.core.Future publish(java.lang.String exchange, java.lang.String routingKey, com.rabbitmq.client.BasicProperties properties, io.vertx.core.buffer.Buffer body) { io.vertx.core.Future ret = delegate.publish(exchange, routingKey, properties, body).map(val -> val); return ret; } /** * Publish a message. * @param exchange * @param routingKey * @param properties * @param body * @return */ public io.reactivex.Completable rxPublish(java.lang.String exchange, java.lang.String routingKey, com.rabbitmq.client.BasicProperties properties, io.vertx.core.buffer.Buffer body) { return AsyncResultCompletable.toCompletable($handler -> { this.publish(exchange, routingKey, properties, body).onComplete($handler); }); } /** * Publish a message and complete when publish confirm has returned. * @param exchange * @param routingKey * @param properties * @param body * @return */ public io.vertx.core.Future publishConfirm(java.lang.String exchange, java.lang.String routingKey, com.rabbitmq.client.BasicProperties properties, io.vertx.core.buffer.Buffer body) { io.vertx.core.Future ret = delegate.publishConfirm(exchange, routingKey, properties, body).map(val -> val); return ret; } /** * Publish a message and complete when publish confirm has returned. * @param exchange * @param routingKey * @param properties * @param body * @return */ public io.reactivex.Single rxPublishConfirm(java.lang.String exchange, java.lang.String routingKey, com.rabbitmq.client.BasicProperties properties, io.vertx.core.buffer.Buffer body) { return AsyncResultSingle.toSingle($handler -> { this.publishConfirm(exchange, routingKey, properties, body).onComplete($handler); }); } public static RabbitMQPublisher newInstance(io.vertx.rabbitmq.RabbitMQPublisher arg) { return arg != null ? new RabbitMQPublisher(arg) : null; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy