如何在vertx中使用Eventbus消息传递? [英] How to use eventbus messaging in vertx?

查看:1004
本文介绍了如何在vertx中使用Eventbus消息传递?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循了那我只有:

➜  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?

推荐答案

如果只想查看事件总线消息传递的工作方式,则只需将两段代码都移动到一个文件中并运行它即可.

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

要集群运行

如果要运行通过集群指定的示例,则可能需要更改您的cluster.xml配置文件,该文件位于vertx安装的conf文件夹中.我不得不更改两行,首先更改

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">

为假:

<multicast enabled="false">

然后更改

<tcp-ip enabled="false">

为真

<tcp-ip enabled="true">

,并确保接口标签具有正确的IP地址.然后,您上面指定的命令将运行.

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

这篇关于如何在vertx中使用Eventbus消息传递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆