本文整理汇总了Java中io.vertx.core.eventbus.EventBus类的典型用法代码示例。如果您正苦于以下问题:Java EventBus类的具体用法?Java EventBus怎么用?Java EventBus使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EventBus类属于io.vertx.core.eventbus包,在下文中一共展示了EventBus类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processOneResult
import io.vertx.core.eventbus.EventBus; //导入依赖的package包/类
protected void processOneResult(final JsonObject dataChange) {
final JsonObject data = dataChange.getJsonObject("data");
final JsonObject payload = data.getJsonObject("payload");
// We send it off to the eventbus and in any case have the
// final destination header set - just in case
final EventBus eb = this.getVertx().eventBus();
final DeliveryOptions opts = new DeliveryOptions();
this.getListenerConfig().getEventBusAddresses().forEach(destination -> {
opts.addHeader(Constants.BUS_FINAL_DESTINATION, destination);
});
// Intermediate step for deduplication of messages
if (this.useDedupService()) {
eb.publish(this.getListenerConfig().getEventBusDedupAddress(), payload, opts);
} else {
this.getListenerConfig().getEventBusAddresses().forEach(destination -> {
try {
eb.publish(destination, payload, opts);
this.logger.info("Sending to [" + destination + "]:" + payload.toString());
} catch (final Throwable t) {
this.logger.error(t.getMessage(), t);
}
});
}
}
示例2: createMessageHandlers
import io.vertx.core.eventbus.EventBus; //导入依赖的package包/类
private static ModuleSystem createMessageHandlers(ModuleSystem module) {
EventBus eventBus = module.require(EventBus.class);
module.require(MessageHandlersBuilder.class).build(
MessageHandlersBuilder.BuildParams.builder()
.module(module)
.flowParamss(ImmutableList.of(
new MessageHandlersBuilder.FlowParams(
Entities.USER_ENTITY,
new FieldExpressionImpl(
"r.id"
)
)
))
.build()
).forEach(addressAndHandler -> {
eventBus.consumer(addressAndHandler.getAddress(), addressAndHandler.getMessageHandler());
});
return module;
}
示例3: start
import io.vertx.core.eventbus.EventBus; //导入依赖的package包/类
@Override
public void start() throws Exception {
JsonObject config = config();
String gremlinServerConfigPath = config.getString("gremlinServerConfigPath");
Server.single.init(gremlinServerConfigPath).start();
client = Client.single.start();
eventBusAddr = config.getString("eventBusAddress");
EventBus eventBus = vertx.eventBus();
eventBus.consumer(eventBusAddr, event -> {
String body = (String) event.body();
logger.info("received from the eventbus of {} : {}", eventBusAddr, body);
GremlinMessage gremlinMessage = Json.decodeValue(body, GremlinMessage.class);
List<Object> submit;
try {
submit = client.submit(gremlinMessage.getGremlinScript(), null, gremlinMessage.getParambindings());
String result = Json.encode(submit);
event.reply(result);
} catch (Exception e) {
logger.error("can't execute script : " + gremlinMessage.getGremlinScript() + " because: " + e.getMessage(), e);
}
});
}
示例4: 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;
}
示例5: processOneResult
import io.vertx.core.eventbus.EventBus; //导入依赖的package包/类
/**
* @see net.wissel.salesforce.vertx.listener.CometD#processOneResult(io.vertx.core.json.JsonObject)
*/
@Override
protected void processOneResult(JsonObject dataChange) {
final JsonObject data = dataChange.getJsonObject("data");
final JsonObject payload = data.getJsonObject("payload");
final String objectType = payload.getString("ObjectType__c");
// We send it off to the eventbus
final EventBus eb = this.getVertx().eventBus();
this.getListenerConfig().getEventBusAddresses().forEach(destination -> {
try {
eb.publish(destination+objectType, payload);
this.logger.info("Sending to [" + destination+objectType + "]:" + payload.toString());
} catch (final Throwable t) {
this.logger.error(t.getMessage(), t);
}
});
}
示例6: 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;
}
示例7: start
import io.vertx.core.eventbus.EventBus; //导入依赖的package包/类
@Override
public void start() {
final EventBus bus = this.vertx.eventBus();
bus.<JsonObject>consumer(ID.Addr.REGISTRY_START, result -> {
final JsonObject data = result.body();
final String name = data.getString(Registry.NAME);
final HttpServerOptions options =
new HttpServerOptions(data.getJsonObject(Registry.OPTIONS));
final String[] uris =
data.getString(Registry.URIS).split(Strings.COMMA);
final Set<String> uriData = new TreeSet<>(Arrays.asList(uris));
// Write the data to registry.
this.registry.registryHttp(name, options, Etat.RUNNING);
this.registry.registryRoute(name, options, uriData);
LOGGER.info(Info.MICRO_REGISTRY_CONSUME, getClass().getSimpleName(),
name, ID.Addr.REGISTRY_START);
});
}
示例8: attack
import io.vertx.core.eventbus.EventBus; //导入依赖的package包/类
@Override
public Handler<RoutingContext> attack(final Event event) {
return Fn.get(() -> (context) -> Responser.exec(() -> {
// 1. Build Envelop
final Envelop request = this.invoke(context, event);
// 2. Build event bus
final Vertx vertx = context.vertx();
final EventBus bus = vertx.eventBus();
// 3. Send message
final String address = this.address(event);
bus.<Envelop>send(address, request, handler -> {
final Envelop response;
if (handler.succeeded()) {
// Request - Response message
response = this.success(address, handler);
} else {
response = this.failure(address, handler);
}
Answer.reply(context, response, event);
});
}, context, event), event);
}
示例9: registerSynonyms
import io.vertx.core.eventbus.EventBus; //导入依赖的package包/类
private void registerSynonyms() {
EventBus eventBus = vertx.eventBus();
eventBus.consumer(WordnetAddresses.SYNONYMS.getAddress(), (Handler<Message<String>>) message -> {
String body = message.body();
IDictionary dictionary = dictionaryCache.getDictionary();
IIndexWord idxWord = dictionary.getIndexWord(body, POS.NOUN);
IWordID wordID = idxWord.getWordIDs().get(0); // 1st meaning
IWord word = dictionary.getWord(wordID);
ISynset synset = word.getSynset();
List<String> synonyms = synset.getWords().stream().map(IWord::getLemma).collect(Collectors.toList());
message.reply(new JsonArray(synonyms));
});
}
示例10: start
import io.vertx.core.eventbus.EventBus; //导入依赖的package包/类
@Override
public void start() throws Exception {
// Retrieve the event bus
EventBus eventBus = vertx.eventBus();
// Execute the given handler every 2000 ms
vertx.setPeriodic(2000, l -> {
// Use the eventBus() method to retrieve the event bus and send a "{"message":hello"} JSON message on the
// "greetings" address.
// 1 - Create the JSON object using the JsonObject class, and `put` the 'message':'hello' entry
// TODO
// 2 - Use the `send` method of the event bus to _send_ the message. Messages sent with the `send` method
// are received by a single consumer. Messages sent with the `publish` method are received by all
// registered consumers.
// TODO
});
}
示例11: AppImpl
import io.vertx.core.eventbus.EventBus; //导入依赖的package包/类
public AppImpl(Config config) {
Objects.requireNonNull(config);
final ModuleSystemBuilder builder = ModuleSystem.builder();
TrackerExporter.exportTo(
TrackerExporter.ExportToParams.builder()
.builder(builder)
.config(config)
.build()
);
module = builder.build();
eventBus = module.require(EventBus.class);
createMessageHandlers(module);
MessageBus messageBus = module.require(MessageBus.class);
}
示例12: registerSingleConfigEntryProvider
import io.vertx.core.eventbus.EventBus; //导入依赖的package包/类
/**
* Registers a handler for accessing single configuration keys (input: String, reply type: String). If no
* config value is present the consumer will reply with a NOT_FOUND failure.
* @param address the event bus address to register.
* @param eventBus the event bus.
* @return the consumer registered.
*/
public static MessageConsumer<String> registerSingleConfigEntryProvider(String address, EventBus eventBus){
MessageConsumer<String> consumer = eventBus.consumer(address);
consumer.handler(h -> {
String key = (String) h.body();
if (key == null) {
h.fail(HttpResponseStatus.BAD_REQUEST.code(), "Missing config key.");
} else {
String value = ConfigurationProvider.getConfiguration().getOrDefault(key, null);
if (value != null) {
h.reply(value);
} else {
h.fail(HttpResponseStatus.NOT_FOUND.code(), "Config key not found: " + key);
}
}
});
return consumer;
}
示例13: registerMultiConfigEntryProvider
import io.vertx.core.eventbus.EventBus; //导入依赖的package包/类
/**
* Registers a handler for accessing multiple configuration keys (input: String[] (Json),
* reply type: Map<String,String></String,String> (Json).
* @param address the event bus address to register.
* @param eventBus the event bus.
* @return the consumer registered.
*/
public static MessageConsumer<String> registerMultiConfigEntryProvider(String address, EventBus eventBus){
MessageConsumer<String> consumer = eventBus.consumer(address);
consumer.handler(h -> {
String val = h.body();
Configuration config = ConfigurationProvider.getConfiguration();
Map<String,String> entries = new TreeMap<>();
if(val!=null){
String[] sections = Json.decodeValue(val, String[].class);
for (String section : sections) {
if(section!=null) {
entries.putAll(config.with(ConfigurationFunctions.section(section)).getProperties());
}
}
}else{
entries.putAll(config.getProperties());
}
h.reply(Json.encode(entries));
});
return consumer;
}
示例14: configureRoute
import io.vertx.core.eventbus.EventBus; //导入依赖的package包/类
private static void configureRoute(Route route, Operation operation, EventBus eventBus) {
Optional.ofNullable(operation.getConsumes()).ifPresent(consumes -> consumes.forEach(route::consumes));
Optional.ofNullable(operation.getProduces()).ifPresent(produces -> produces.forEach(route::produces));
route.handler(context -> {
try {
JsonObject message = new JsonObject();
operation.getParameters().forEach( parameter -> {
String name = parameter.getName();
String value = PARAMETER_EXTRACTORS.get(parameter.getIn()).extract(name, parameter.getRequired(), context.request());
message.put(name, value);
});
eventBus.<JsonObject>send(operation.getOperationId(), message, operationResponse -> {
if (operationResponse.succeeded()) {
context.response().end(operationResponse.result().body().encode());
} else {
internalServerErrorEnd(context.response());
}
});
} catch (RuntimeException e) {
badRequestEnd(context.response());
}
});
}
示例15: initialize
import io.vertx.core.eventbus.EventBus; //导入依赖的package包/类
@Override
public void initialize(Vertx vertx, JsonObject config, Future<Void> complete) {
//eventbus consumer
EventBus eb = vertx.eventBus();
Lists.newArrayList(ServiceLoader.load(ApiCmdFactory.class))
.stream()
.map(f -> f.create(vertx, config))
.forEach(cmd -> {
String address = cmdAddress(cmd.cmd());
Log.create(LOGGER)
.setEvent("api.cmd.register")
.addData("address", address)
.addData("cmd", cmd.cmd())
.info();
eb.<JsonObject>consumer(address, msg -> {
try {
consumer(cmd, msg);
} catch (Exception e) {
EventbusUtils.onFailure(msg, 0, e);
}
});
});
complete.complete();
}