use of io.vertx.proton.ProtonConnection in project vertx-proton by vert-x3.
the class Sender method main.
public static void main(String[] args) throws Exception {
try {
Vertx vertx = Vertx.vertx();
ProtonClient client = ProtonClient.create(vertx);
// Connect, then use the event loop thread to process the connection
client.connect("localhost", 5672, res -> {
Context ctx = Vertx.currentContext();
if (res.succeeded()) {
System.out.println("We're connected");
ProtonConnection connection = res.result();
connection.open();
Subscriber<Message> producerSubscriber = ProtonStreams.createProducer(connection, "queue");
Publisher<Message> publisher = Flowable.range(1, COUNT).map(i -> {
Message m = Proton.message();
m.setBody(new AmqpValue("Hello " + i));
return m;
}).doFinally(() -> {
ctx.runOnContext(x -> {
System.out.println("Publisher finished, closing connection.");
connection.closeHandler(y -> {
System.out.println("Connection closed.");
connection.disconnect();
vertx.close();
}).close();
});
});
publisher.subscribe(producerSubscriber);
} else {
System.out.println("Failed to connect, exiting: " + res.cause());
System.exit(1);
}
});
} catch (Exception exp) {
System.out.println("Caught exception, exiting.");
exp.printStackTrace(System.out);
System.exit(1);
}
}
use of io.vertx.proton.ProtonConnection in project vertx-proton by vert-x3.
the class MessagePublisherVerificationTckTest method createPublisher.
@Override
public Publisher<Message> createPublisher(long elements) {
int actualPort = server.actualPort();
ProtonClient client = ProtonClient.create(vertx);
AtomicReference<Publisher<Message>> ref = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
client.connect("localhost", actualPort, result -> {
if (result.succeeded()) {
ProtonConnection conn = result.result();
conn.open();
ProtonPublisher<Message> stream = ProtonStreams.createConsumer(conn, testName);
((ProtonPublisherWrapperImpl) stream).setEmitOnConnectionEnd(false);
ref.set(stream);
} else {
LOG.error("Connection failed");
}
latch.countDown();
});
try {
LOG.trace("Awaiting connection");
boolean res = latch.await(2, TimeUnit.SECONDS);
LOG.trace("Client connected: " + res);
} catch (InterruptedException e) {
throw new RuntimeException("Interrupted while creating publisher", e);
}
return ref.get();
}
use of io.vertx.proton.ProtonConnection in project vertx-proton by vert-x3.
the class VertxProtonExamples method example1.
public void example1(Vertx vertx) {
ProtonClient client = ProtonClient.create(vertx);
// Connect, then use the event loop thread to process things thereafter
client.connect("hostname", 5672, "username", "password", connectResult -> {
if (connectResult.succeeded()) {
connectResult.result().setContainer("my-container/client-id").openHandler(openResult -> {
if (openResult.succeeded()) {
ProtonConnection conn = openResult.result();
// Create senders, receivers etc..
}
}).open();
}
});
}
Aggregations