本文整理汇总了Java中io.vertx.core.eventbus.EventBus.send方法的典型用法代码示例。如果您正苦于以下问题:Java EventBus.send方法的具体用法?Java EventBus.send怎么用?Java EventBus.send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.core.eventbus.EventBus
的用法示例。
在下文中一共展示了EventBus.send方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAuthInfo
import io.vertx.core.eventbus.EventBus; //导入方法依赖的package包/类
/**
* Check for the Authentication info if required
*
* @return a future that resolves when successful got AuthInfo
*/
private Future<AuthInfo> getAuthInfo() {
Future<AuthInfo> result;
final String authName = this.getConsumerConfig().getAuthName();
if ((this.authInfo == null) && (authName != null)) {
result = Future.future();
final EventBus eb = this.getVertx().eventBus();
final String address = Constants.BUS_AUTHREQUEST + authName;
eb.send(address, null, replyHandler -> {
if (replyHandler.succeeded()) {
this.authInfo = (AuthInfo) replyHandler.result().body();
result.complete(this.authInfo);
} else {
result.fail(replyHandler.cause());
}
});
} else {
result = Future.succeededFuture(this.authInfo);
}
return result;
}
示例2: getAuthInfo
import io.vertx.core.eventbus.EventBus; //导入方法依赖的package包/类
private Future<AuthInfo> getAuthInfo() {
Future<AuthInfo> result;
if (this.authInfo == null) {
result = Future.future();
final EventBus eb = this.getVertx().eventBus();
final String address = Constants.BUS_AUTHREQUEST + this.getListenerConfig().getAuthName();
eb.send(address, null, replyHandler -> {
if (replyHandler.succeeded()) {
this.authInfo = (AuthInfo) replyHandler.result().body();
result.complete(this.authInfo);
} else {
result.fail(replyHandler.cause());
}
});
} else {
result = Future.succeededFuture(this.authInfo);
}
return result;
}
示例3: scheduling
import io.vertx.core.eventbus.EventBus; //导入方法依赖的package包/类
static void scheduling(Vertx vertx) {
EventBus eventBus = vertx.eventBus();
// Consumer of the timer events
MessageConsumer<JsonObject> consumer = eventBus.consumer("scheduler:timer");
// Listens and prints timer events. When timer completes stops the Vertx
consumer.handler (
message -> {
JsonObject event = message.body();
if (event.getString("event").equals("complete")) {
System.out.println("completed");
vertx.close();
}
else {
System.out.println(event);
}
}
);
// Create new timer
eventBus.send (
"chime",
(new JsonObject()).put("operation", "create").put("name", "scheduler:timer")
.put("publish", false).put("max count", 3)
.put("description", (new JsonObject()).put("type", "interval").put("delay", 1)),
ar -> {
if (ar.succeeded()) {
System.out.println("Scheduling started: " + ar.result().body());
}
else {
System.out.println("Message failed: " + ar.cause());
vertx.close();
}
}
);
}
示例4: retry
import io.vertx.core.eventbus.EventBus; //导入方法依赖的package包/类
/**
* Retry send request item to retry queue of planner
*/
private void retry() {
int retried = request.getRetried();
if (retried < retryTimes) {
request.setRetried(retried + 1);
EventBus eb = executor.getEventBus();
eb.send(MessageAddress.RETRY_URL_LISTENER, request);
} else {
logger.error("Failed to download {} after {} retries!", url, retryTimes);
}
}
示例5: process
import io.vertx.core.eventbus.EventBus; //导入方法依赖的package包/类
@Override
public boolean process(Exchange exchange, AsyncCallback callback) {
EventBus eventBus = getEndpoint().getEventBus();
if (eventBus == null) {
exchange.setException(new IllegalStateException("EventBus is not started or not configured"));
callback.done(true);
return true;
}
String address = getEndpoint().getAddress();
boolean reply = ExchangeHelper.isOutCapable(exchange);
boolean pubSub = getEndpoint().isPubSub();
Object body = getVertxBody(exchange);
if (body != null) {
if (reply) {
LOG.debug("Sending to: {} with body: {}", address, body);
eventBus.send(address, body, new CamelReplyHandler(exchange, callback));
return false;
} else {
if (pubSub) {
LOG.debug("Publishing to: {} with body: {}", address, body);
eventBus.publish(address, body);
} else {
LOG.debug("Sending to: {} with body: {}", address, body);
eventBus.send(address, body);
}
callback.done(true);
return true;
}
}
exchange.setException(new InvalidPayloadRuntimeException(exchange, String.class));
callback.done(true);
return true;
}
示例6: listenCurrentTrack
import io.vertx.core.eventbus.EventBus; //导入方法依赖的package包/类
static void listenCurrentTrack(final EventBus eventBus) {
eventBus.consumer(TRACK_CHANGED).handler(event -> eventBus.publish(AUDIO_CURRENT, event.body()));
eventBus.send(GET_CURRENT_TRACK, null, response -> {
if (response.succeeded()) {
eventBus.publish(AUDIO_CURRENT, response.result().body());
} else {
eventBus.publish(AUDIO_CURRENT, new JsonObject());
}
});
}
示例7: headers
import io.vertx.core.eventbus.EventBus; //导入方法依赖的package包/类
public void headers(EventBus eventBus) {
DeliveryOptions options = new DeliveryOptions();
options.addHeader("some-header", "some-value");
eventBus.send("news.uk.sport", "Yay! Someone kicked a ball", options);
}
示例8: handleRestRequest
import io.vertx.core.eventbus.EventBus; //导入方法依赖的package包/类
/**
* handles REST requests
*
* @param eventBus the vert.x event bus
* @param request the http request
* @param url the request URL
* @param parameters the request parameters
* @param mimes the service mime types
* @param timeout the default timeout
*/
private void handleRestRequest(final EventBus eventBus,
HttpServerRequest request,
final String url,
final Parameter parameters,
final List<String> mimes,
final int timeout) {
eventBus.
send(
url,
getSerializedParameters(parameters),
new DeliveryOptions().setSendTimeout(timeout),
event -> createRestResponse(request, mimes, event));
}
示例9: forward
import io.vertx.core.eventbus.EventBus; //导入方法依赖的package包/类
private static void forward(BridgeEvent be, EventBus eb) {
String type = be.type().toString();
eb.send(type, type);
be.complete(true);
}
示例10: example10
import io.vertx.core.eventbus.EventBus; //导入方法依赖的package包/类
public void example10(EventBus eventBus, MessageCodec myCodec) {
eventBus.registerCodec(myCodec);
DeliveryOptions options = new DeliveryOptions().setCodecName(myCodec.name());
eventBus.send("orders", new MyPOJO(), options);
}
示例11: example11
import io.vertx.core.eventbus.EventBus; //导入方法依赖的package包/类
public void example11(EventBus eventBus, MessageCodec myCodec) {
eventBus.registerDefaultCodec(MyPOJO.class, myCodec);
eventBus.send("orders", new MyPOJO());
}