use of io.vertx.core.eventbus.DeliveryOptions in project vert.x by eclipse.
the class MetricsTest method testReplyFailureTimeout2.
@Test
public void testReplyFailureTimeout2() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
EventBus eb = vertx.eventBus();
eb.consumer(ADDRESS1, msg -> {
msg.reply("juu", new DeliveryOptions().setSendTimeout(10), ar -> {
assertTrue(ar.failed());
latch.countDown();
});
});
eb.send(ADDRESS1, "bar", ar -> {
});
awaitLatch(latch);
FakeEventBusMetrics metrics = FakeMetricsBase.getMetrics(eb);
assertEquals(1, metrics.getReplyFailureAddresses().size());
assertEquals(Collections.singletonList(ReplyFailure.TIMEOUT), metrics.getReplyFailures());
}
use of io.vertx.core.eventbus.DeliveryOptions in project vert.x by eclipse.
the class EventBusFlowControlTest method testFlowControlWithOptions.
@Test
public void testFlowControlWithOptions() {
MessageProducer<String> prod = eb.sender("some-address");
prod.deliveryOptions(new DeliveryOptions().addHeader("foo", "bar"));
int numBatches = 1000;
int wqms = 2000;
prod.setWriteQueueMaxSize(wqms);
MessageConsumer<String> consumer = eb.consumer("some-address");
AtomicInteger cnt = new AtomicInteger();
consumer.handler(msg -> {
int c = cnt.incrementAndGet();
if (c == numBatches * wqms) {
testComplete();
}
});
vertx.runOnContext(v -> {
sendBatch(prod, wqms, numBatches, 0);
});
await(10, TimeUnit.SECONDS);
}
use of io.vertx.core.eventbus.DeliveryOptions in project vertx-tcp-eventbus-bridge by vert-x3.
the class TcpEventBusBridgeImpl method doSendOrPub.
private void doSendOrPub(boolean send, NetSocket socket, String address, JsonObject msg, Map<String, MessageConsumer<?>> registry, Map<String, Message<JsonObject>> replies) {
final JsonObject body = msg.getJsonObject("body");
final JsonObject headers = msg.getJsonObject("headers");
// default to message
final String type = msg.getString("type", "message");
DeliveryOptions deliveryOptions = parseMsgHeaders(new DeliveryOptions(), headers);
switch(type) {
case "send":
if (checkMatches(true, address, replies)) {
final String replyAddress = msg.getString("replyAddress");
if (replyAddress != null) {
eb.send(address, body, deliveryOptions, (AsyncResult<Message<JsonObject>> res1) -> {
if (res1.failed()) {
sendErrFrame(address, replyAddress, (ReplyException) res1.cause(), socket);
} else {
final Message<JsonObject> response = res1.result();
final JsonObject responseHeaders = new JsonObject();
// clone the headers from / to
for (Map.Entry<String, String> entry : response.headers()) {
responseHeaders.put(entry.getKey(), entry.getValue());
}
if (response.replyAddress() != null) {
replies.put(response.replyAddress(), response);
}
sendFrame("message", replyAddress, response.replyAddress(), responseHeaders, true, response.body(), socket);
}
});
} else {
if (replies.containsKey(address)) {
replies.get(address).reply(body, deliveryOptions);
} else {
eb.send(address, body, deliveryOptions);
}
}
// replies are a one time off operation
replies.remove(address);
} else {
sendErrFrame("access_denied", socket);
}
break;
case "publish":
if (checkMatches(true, address)) {
eb.publish(address, body, deliveryOptions);
} else {
sendErrFrame("access_denied", socket);
}
break;
case "register":
if (checkMatches(false, address)) {
registry.put(address, eb.consumer(address, (Message<JsonObject> res1) -> {
// save a reference to the message so tcp bridged messages can be replied properly
if (res1.replyAddress() != null) {
replies.put(res1.replyAddress(), res1);
}
final JsonObject responseHeaders = new JsonObject();
// clone the headers from / to
for (Map.Entry<String, String> entry : res1.headers()) {
responseHeaders.put(entry.getKey(), entry.getValue());
}
sendFrame("message", res1.address(), res1.replyAddress(), responseHeaders, res1.isSend(), res1.body(), socket);
}));
} else {
sendErrFrame("access_denied", socket);
}
break;
case "unregister":
if (checkMatches(false, address)) {
MessageConsumer<?> consumer = registry.remove(address);
if (consumer != null) {
consumer.unregister();
} else {
sendErrFrame("unknown_address", socket);
}
} else {
sendErrFrame("access_denied", socket);
}
break;
default:
sendErrFrame("unknown_type", socket);
break;
}
}
use of io.vertx.core.eventbus.DeliveryOptions in project vertx-examples by vert-x3.
the class ProcessorServiceVertxEBProxy method process.
@Override
public void process(JsonObject document, Handler<AsyncResult<JsonObject>> resultHandler) {
if (closed) {
resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
return;
}
JsonObject _json = new JsonObject();
_json.put("document", document);
DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
_deliveryOptions.addHeader("action", "process");
_vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> {
if (res.failed()) {
resultHandler.handle(Future.failedFuture(res.cause()));
} else {
resultHandler.handle(Future.succeededFuture(res.result().body()));
}
});
}
use of io.vertx.core.eventbus.DeliveryOptions in project vertx-examples by vert-x3.
the class SomeDatabaseServiceVertxEBProxy method getDataById.
@Override
public SomeDatabaseService getDataById(int id, Handler<AsyncResult<JsonObject>> resultHandler) {
if (closed) {
resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
return this;
}
JsonObject _json = new JsonObject();
_json.put("id", id);
DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
_deliveryOptions.addHeader("action", "getDataById");
_vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> {
if (res.failed()) {
resultHandler.handle(Future.failedFuture(res.cause()));
} else {
resultHandler.handle(Future.succeededFuture(res.result().body()));
}
});
return this;
}
Aggregations