How to use eventbus messaging in vertx?

怎甘沉沦 提交于 2019-12-11 16:19:33

问题


I followed the instructions in sample and ran:

vertx run eventbus_pointtopoint/receiver.rb -cluster
vertx run eventbus_pointtopoint/sender.rb -cluster

Then I only got:

➜  ruby  vertx run eventbus_pointtopoint/receiver.rb -cluster
Starting clustering...
No cluster-host specified so using address 192.168.56.1
Succeeded in deploying verticle

➜  ruby  vertx run eventbus_pointtopoint/sender.rb -cluster
Starting clustering...
No cluster-host specified so using address 192.168.56.1
Succeeded in deploying verticle

But no message received. What am I doing wrong?


回答1:


If you just want to see how event bus messaging works you can just move both pieces of code into the one file and run it.

require "vertx"
include Vertx

EventBus.register_handler('ping-address') do |msg|
  puts "Received message: #{msg.body}"
  # Now reply to it
  msg.reply('pong!')
end

Vertx::set_periodic(1000) do
  EventBus.send('ping-address', 'ping') do |reply|
    puts "Received reply: #{reply.body}"
  end
end

To run clustered

If you want to run the example specified with clustering you may need to change your cluster.xml config file, it is in the conf folder of your vertx install. I had to change two lines, first change

<multicast enabled="true">

to false:

<multicast enabled="false">

then change

<tcp-ip enabled="false">

to true

<tcp-ip enabled="true">

and make sure the interface tag has the correct IP address. Then the commands you specified above should run.



来源:https://stackoverflow.com/questions/27440218/how-to-use-eventbus-messaging-in-vertx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!