本文整理汇总了Java中io.vertx.core.eventbus.EventBus.consumer方法的典型用法代码示例。如果您正苦于以下问题:Java EventBus.consumer方法的具体用法?Java EventBus.consumer怎么用?Java EventBus.consumer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.core.eventbus.EventBus
的用法示例。
在下文中一共展示了EventBus.consumer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
});
}
示例2: 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);
});
}
示例3: 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));
});
}
示例4: 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;
}
示例5: 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;
}
示例6: run
import io.vertx.core.eventbus.EventBus; //导入方法依赖的package包/类
@Override
public void run(AsyncResultHandler<Void> startupHandler, Handler<DuplexStream<Buffer, Buffer>> duplexStreamHandler) {
final EventBus eventBus = vertx.eventBus();
inputConsumer = eventBus.consumer(configObj.getString("input.address"));
outputPublisher = eventBus.publisher(configObj.getString("output.address"));
completePublisher = eventBus.publisher(configObj.getString("complete.address"));
closePublisher = eventBus.publisher(configObj.getString("close.address"));
final EventBusClosableWriteStream eventBusStream = new EventBusClosableWriteStream(inputConsumer, outputPublisher);
final DuplexStream<Buffer, Buffer> duplexStream = new DuplexStream<>(inputConsumer.bodyStream(), eventBusStream);
duplexStream
.closeHandler(v -> {
closePublisher.write(Buffer.buffer("Closed"));
})
.writeCompleteHandler(pack -> {
completePublisher.write(Buffer.buffer("Ok"));
});
vertx.runOnContext(v -> {
duplexStreamHandler.handle(duplexStream);
});
startupHandler.handle(Future.succeededFuture());
}
示例7: register
import io.vertx.core.eventbus.EventBus; //导入方法依赖的package包/类
/**
* Register the proxy handle on the event bus.
*
* @param eventBus the event bus
* @param address the proxy address
*/
public MessageConsumer<JsonObject> register(EventBus eventBus, String address, List<Function<Message<JsonObject>, Future<Message<JsonObject>>>> interceptors) {
Handler<Message<JsonObject>> handler = this::handle;
if (interceptors != null) {
for (Function<Message<JsonObject>, Future<Message<JsonObject>>> interceptor : interceptors) {
Handler<Message<JsonObject>> prev = handler;
handler = msg -> {
Future<Message<JsonObject>> fut = interceptor.apply(msg);
fut.setHandler(ar -> {
if (ar.succeeded()) {
prev.handle(msg);
} else {
ReplyException exception = (ReplyException) ar.cause();
msg.fail(exception.failureCode(), exception.getMessage());
}
});
};
}
}
consumer = eventBus.consumer(address, handler);
return consumer;
}
示例8: startListening
import io.vertx.core.eventbus.EventBus; //导入方法依赖的package包/类
@Override
public SFDCVerticle startListening() {
this.logger.info("Start listening:" + this.getClass().getName());
// Listen on the event bus
final EventBus eb = this.vertx.eventBus();
this.consumer = eb.consumer(this.getConsumerConfig().getEventBusAddress());
this.logger.info(this.getClass().getName() + " listening on " + this.consumer.address());
this.consumer.handler(this::processIncoming);
// Done
this.listening = true;
return this;
}
示例9: startListening
import io.vertx.core.eventbus.EventBus; //导入方法依赖的package包/类
@Override
public SFDCVerticle startListening() {
this.logger.info("Start listening:" + this.getClass().getName());
// Listen on the event bus
final EventBus eb = this.vertx.eventBus();
this.dedupConsumer = eb.consumer(Constants.BUS_DEDUP_PREFIX + this.getDedupConfig().getInstanceName());
this.logger.info(this.getClass().getName() + " listening on " + this.dedupConsumer.address());
this.dedupConsumer.handler(this::processIncoming);
// Done
this.listening = true;
return this;
}
示例10: start
import io.vertx.core.eventbus.EventBus; //导入方法依赖的package包/类
@Override
public void start() {
final EventBus bus = this.vertx.eventBus();
bus.<JsonObject>consumer(ID.Addr.IPC_START, result -> {
final JsonObject data = result.body();
final ServidorOptions options = new ServidorOptions(data);
// Write the data to registry.
this.registry.registryRpc(options, Etat.RUNNING);
this.registry.registryIpcs(options, Tunnel.IPCS.keySet());
LOGGER.info(Info.MICRO_REGISTRY_CONSUME, getClass().getSimpleName(),
options.getName(), ID.Addr.IPC_START);
});
}
示例11: 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();
}
}
);
}
示例12: registerNameFinder
import io.vertx.core.eventbus.EventBus; //导入方法依赖的package包/类
private void registerNameFinder() {
EventBus eventBus = vertx.eventBus();
eventBus.consumer(NlpAddresses.PERSONNAME.getAddress(), (Handler<Message<String[]>>) message -> {
String[] tokens = message.body();
List<PersonName> names = new ArrayList<>();
Span nameSpans[] = nameFinder.find(tokens);
double[] spanProbs = nameFinder.probs(nameSpans);
for (int i = 0; i < nameSpans.length; i++) {
Span nameSpan = nameSpans[i];
int start = nameSpan.getStart();
int end = nameSpan.getEnd() - 1;
String name;
if (start == end) {
name = tokens[start];
} else {
name = tokens[start] + " " + tokens[end];
}
double probability = spanProbs[i];
String[] nameTokens = Arrays.copyOfRange(tokens, start, end + 1);
names.add(new PersonName(name, nameTokens, probability));
}
message.reply(names);
});
}
示例13: registerConfigurationInjector
import io.vertx.core.eventbus.EventBus; //导入方法依赖的package包/类
/**
* Registers a handler for configuring any objects sent via the message bus using Tamaya's injection API.
* @param address the event bus address to register.
* @param eventBus the event bus.
* @return the consumer registered.
*/
public static MessageConsumer<Object> registerConfigurationInjector(String address, EventBus eventBus){
MessageConsumer<Object> consumer = eventBus.consumer(address);
consumer.handler(h -> {
Object o = h.body();
if(o==null){
h.fail(HttpResponseStatus.BAD_REQUEST.code(), "Required object to configure is missing.");
}else {
ConfigurationInjection.getConfigurationInjector().configure(o);
h.reply("OK");
}
});
return consumer;
}
示例14: start
import io.vertx.core.eventbus.EventBus; //导入方法依赖的package包/类
@Override
public void start() throws Exception {
EventBus eb = vertx.eventBus();
producer = this.createKafkaProducer();
LOGGER.info("Created consumer");
eb.consumer(Constants.EVENTBUS_ADDRESS, message -> {
try {
MultiMap multiMap = message.headers();
String topic = multiMap.get(Constants.TOPIC);
String messageKey = multiMap.get(Constants.MESSAGE_KEY);
Integer messageBody = (Integer)message.body();
LOGGER.info("Sending body: " + messageBody);
Future<RecordMetadata> future = producer.send(new ProducerRecord<>(topic, messageKey, createMessage(messageBody)));
RecordMetadata meta = future.get();
// Now send back reply
message.reply("OK");
} catch (Exception exc) {
LOGGER.error(exc);
}
});
LOGGER.info("Receiver ready!");
}
示例15: start
import io.vertx.core.eventbus.EventBus; //导入方法依赖的package包/类
@Override
public void start() throws Exception {
EventBus eb = vertx.eventBus();
kinesisAsyncClient = createClient();
eb.consumer(Constants.EVENTBUS_ADDRESS, message -> {
try {
MultiMap multiMap = message.headers();
String partitionKey = multiMap.get(Constants.MESSAGE_KEY);
Integer randomId = (Integer)message.body();
LOGGER.info("Sending body: " + randomId + " from KinesisVerticle");
byte [] byteMessage = createMessage(randomId);
ByteBuffer buf = ByteBuffer.wrap(byteMessage);
sendMessageToKinesis(buf, partitionKey);
// Now send back reply
message.reply("OK");
}
catch (KinesisException exc) {
LOGGER.error(exc);
}
});
LOGGER.info("Receiver ready!");
}