Class: Vertx::EventBus

Inherits:
Object
  • Object
show all
Includes:
Measured
Defined in:
/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/event_bus.rb

Overview

A Vert.x event-bus is a light-weight distributed messaging system which allows different parts of your application, or different applications and services to communicate with each in a loosely coupled way.

An event-bus supports publish-subscribe messaging, point-to-point messaging and request-response messaging.

Message delivery is best-effort and messages can be lost if failure of all or part of the event bus occurs.

Please refer to the documentation for more information on the event bus.

Constant Summary

@@j_api_type =
Object.new

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Boolean) accept?(obj)

Returns:

  • (Boolean)

30
31
32
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/event_bus.rb', line 30

def @@j_api_type.accept?(obj)
  obj.class == EventBus
end

+ (Object) j_api_type


39
40
41
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/event_bus.rb', line 39

def self.j_api_type
  @@j_api_type
end

+ (Object) j_class


42
43
44
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/event_bus.rb', line 42

def self.j_class
  Java::IoVertxCoreEventbus::EventBus.java_class
end

+ (Object) unwrap(obj)


36
37
38
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/event_bus.rb', line 36

def @@j_api_type.unwrap(obj)
  obj.j_del
end

+ (Object) wrap(obj)


33
34
35
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/event_bus.rb', line 33

def @@j_api_type.wrap(obj)
  EventBus.new(obj)
end

Instance Method Details

- (self) add_inbound_interceptor { ... }

Add an interceptor that will be called whenever a message is received by Vert.x

Yields:

  • the interceptor

Returns:

  • (self)

Raises:

  • (ArgumentError)

180
181
182
183
184
185
186
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/event_bus.rb', line 180

def add_inbound_interceptor
  if block_given?
    @j_del.java_method(:addInboundInterceptor, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::Vertx::DeliveryContext, nil)) }))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling add_inbound_interceptor()"
end

- (self) add_outbound_interceptor { ... }

Add an interceptor that will be called whenever a message is sent from Vert.x

Yields:

  • the interceptor

Returns:

  • (self)

Raises:

  • (ArgumentError)

160
161
162
163
164
165
166
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/event_bus.rb', line 160

def add_outbound_interceptor
  if block_given?
    @j_del.java_method(:addOutboundInterceptor, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::Vertx::DeliveryContext, nil)) }))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling add_outbound_interceptor()"
end

- (::Vertx::MessageConsumer) consumer(address = nil) { ... }

Create a consumer and register it against the specified address.

Parameters:

  • address (String) (defaults to: nil)
    the address that will register it at

Yields:

  • the handler that will process the received messages

Returns:

Raises:

  • (ArgumentError)

111
112
113
114
115
116
117
118
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/event_bus.rb', line 111

def consumer(address=nil)
  if address.class == String && !block_given?
    return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:consumer, [Java::java.lang.String.java_class]).call(address),::Vertx::MessageConsumer, nil)
  elsif address.class == String && block_given?
    return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:consumer, [Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(address,(Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::Vertx::Message, nil)) })),::Vertx::MessageConsumer, nil)
  end
  raise ArgumentError, "Invalid arguments when calling consumer(#{address})"
end

- (::Vertx::MessageConsumer) local_consumer(address = nil) { ... }

Like #consumer but the address won't be propagated across the cluster.

Parameters:

  • address (String) (defaults to: nil)
    the address that will register it at

Yields:

  • the handler that will process the received messages

Returns:

Raises:

  • (ArgumentError)

123
124
125
126
127
128
129
130
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/event_bus.rb', line 123

def local_consumer(address=nil)
  if address.class == String && !block_given?
    return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:localConsumer, [Java::java.lang.String.java_class]).call(address),::Vertx::MessageConsumer, nil)
  elsif address.class == String && block_given?
    return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:localConsumer, [Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(address,(Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::Vertx::Message, nil)) })),::Vertx::MessageConsumer, nil)
  end
  raise ArgumentError, "Invalid arguments when calling local_consumer(#{address})"
end

- (true, false) metrics_enabled?

Whether the metrics are enabled for this measured object

Returns:

  • (true, false)
    true if metrics are enabled

Raises:

  • (ArgumentError)

47
48
49
50
51
52
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/event_bus.rb', line 47

def metrics_enabled?
  if !block_given?
    return @j_del.java_method(:isMetricsEnabled, []).call()
  end
  raise ArgumentError, "Invalid arguments when calling metrics_enabled?()"
end

- (self) publish(address = nil, message = nil, options = nil)

Like #publish but specifying options that can be used to configure the delivery.

Parameters:

  • address (String) (defaults to: nil)
    the address to publish it to
  • message (Object) (defaults to: nil)
    the message, may be null
  • options (Hash) (defaults to: nil)
    the delivery options

Returns:

  • (self)

Raises:

  • (ArgumentError)

97
98
99
100
101
102
103
104
105
106
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/event_bus.rb', line 97

def publish(address=nil,message=nil,options=nil)
  if address.class == String && ::Vertx::Util::unknown_type.accept?(message) && !block_given? && options == nil
    @j_del.java_method(:publish, [Java::java.lang.String.java_class,Java::java.lang.Object.java_class]).call(address,::Vertx::Util::Utils.to_object(message))
    return self
  elsif address.class == String && ::Vertx::Util::unknown_type.accept?(message) && options.class == Hash && !block_given?
    @j_del.java_method(:publish, [Java::java.lang.String.java_class,Java::java.lang.Object.java_class,Java::IoVertxCoreEventbus::DeliveryOptions.java_class]).call(address,::Vertx::Util::Utils.to_object(message),Java::IoVertxCoreEventbus::DeliveryOptions.new(::Vertx::Util::Utils.to_json_object(options)))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling publish(#{address},#{message},#{options})"
end

- (::Vertx::MessageProducer) publisher(address = nil, options = nil)

Like #publisher but specifying delivery options that will be used for configuring the delivery of the message.

Parameters:

  • address (String) (defaults to: nil)
    the address to publish it to
  • options (Hash) (defaults to: nil)
    the delivery options

Returns:

Raises:

  • (ArgumentError)

149
150
151
152
153
154
155
156
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/event_bus.rb', line 149

def publisher(address=nil,options=nil)
  if address.class == String && !block_given? && options == nil
    return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:publisher, [Java::java.lang.String.java_class]).call(address),::Vertx::MessageProducer, nil)
  elsif address.class == String && options.class == Hash && !block_given?
    return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:publisher, [Java::java.lang.String.java_class,Java::IoVertxCoreEventbus::DeliveryOptions.java_class]).call(address,Java::IoVertxCoreEventbus::DeliveryOptions.new(::Vertx::Util::Utils.to_json_object(options))),::Vertx::MessageProducer, nil)
  end
  raise ArgumentError, "Invalid arguments when calling publisher(#{address},#{options})"
end

- (self) remove_inbound_interceptor { ... }

Remove an interceptor that was added by #add_inbound_interceptor

Yields:

  • the interceptor

Returns:

  • (self)

Raises:

  • (ArgumentError)

190
191
192
193
194
195
196
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/event_bus.rb', line 190

def remove_inbound_interceptor
  if block_given?
    @j_del.java_method(:removeInboundInterceptor, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::Vertx::DeliveryContext, nil)) }))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling remove_inbound_interceptor()"
end

- (self) remove_outbound_interceptor { ... }

Remove an interceptor that was added by #add_outbound_interceptor

Yields:

  • the interceptor

Returns:

  • (self)

Raises:

  • (ArgumentError)

170
171
172
173
174
175
176
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/event_bus.rb', line 170

def remove_outbound_interceptor
  if block_given?
    @j_del.java_method(:removeOutboundInterceptor, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::Vertx::DeliveryContext, nil)) }))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling remove_outbound_interceptor()"
end

- (self) request(address = nil, message = nil, options = nil) { ... }

Like #request but specifying options that can be used to configure the delivery.

Parameters:

  • address (String) (defaults to: nil)
    the address to send it to
  • message (Object) (defaults to: nil)
    the message body, may be null
  • options (Hash) (defaults to: nil)
    delivery options

Yields:

  • reply handler will be called when any reply from the recipient is received

Returns:

  • (self)

Raises:

  • (ArgumentError)

82
83
84
85
86
87
88
89
90
91
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/event_bus.rb', line 82

def request(address=nil,message=nil,options=nil)
  if address.class == String && ::Vertx::Util::unknown_type.accept?(message) && block_given? && options == nil
    @j_del.java_method(:request, [Java::java.lang.String.java_class,Java::java.lang.Object.java_class,Java::IoVertxCore::Handler.java_class]).call(address,::Vertx::Util::Utils.to_object(message),(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::Vertx::Message, nil) : nil) }))
    return self
  elsif address.class == String && ::Vertx::Util::unknown_type.accept?(message) && options.class == Hash && block_given?
    @j_del.java_method(:request, [Java::java.lang.String.java_class,Java::java.lang.Object.java_class,Java::IoVertxCoreEventbus::DeliveryOptions.java_class,Java::IoVertxCore::Handler.java_class]).call(address,::Vertx::Util::Utils.to_object(message),Java::IoVertxCoreEventbus::DeliveryOptions.new(::Vertx::Util::Utils.to_json_object(options)),(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::Vertx::Message, nil) : nil) }))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling request(#{address},#{message},#{options})"
end

- (self) send(address = nil, message = nil, options = nil) { ... }

Like #send but specifying a replyHandler that will be called if the recipient subsequently replies to the message.

Parameters:

  • address (String) (defaults to: nil)
    the address to send it to
  • message (Object) (defaults to: nil)
    the message, may be null
  • options (Hash) (defaults to: nil)
    delivery options

Yields:

  • reply handler will be called when any reply from the recipient is received, may be null

Returns:

  • (self)

Raises:

  • (ArgumentError)

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/event_bus.rb', line 60

def send(address=nil,message=nil,options=nil)
  if address.class == String && ::Vertx::Util::unknown_type.accept?(message) && !block_given? && options == nil
    @j_del.java_method(:send, [Java::java.lang.String.java_class,Java::java.lang.Object.java_class]).call(address,::Vertx::Util::Utils.to_object(message))
    return self
  elsif address.class == String && ::Vertx::Util::unknown_type.accept?(message) && block_given? && options == nil
    @j_del.java_method(:send, [Java::java.lang.String.java_class,Java::java.lang.Object.java_class,Java::IoVertxCore::Handler.java_class]).call(address,::Vertx::Util::Utils.to_object(message),(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::Vertx::Message, nil) : nil) }))
    return self
  elsif address.class == String && ::Vertx::Util::unknown_type.accept?(message) && options.class == Hash && !block_given?
    @j_del.java_method(:send, [Java::java.lang.String.java_class,Java::java.lang.Object.java_class,Java::IoVertxCoreEventbus::DeliveryOptions.java_class]).call(address,::Vertx::Util::Utils.to_object(message),Java::IoVertxCoreEventbus::DeliveryOptions.new(::Vertx::Util::Utils.to_json_object(options)))
    return self
  elsif address.class == String && ::Vertx::Util::unknown_type.accept?(message) && options.class == Hash && block_given?
    @j_del.java_method(:send, [Java::java.lang.String.java_class,Java::java.lang.Object.java_class,Java::IoVertxCoreEventbus::DeliveryOptions.java_class,Java::IoVertxCore::Handler.java_class]).call(address,::Vertx::Util::Utils.to_object(message),Java::IoVertxCoreEventbus::DeliveryOptions.new(::Vertx::Util::Utils.to_json_object(options)),(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::Vertx::Message, nil) : nil) }))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling send(#{address},#{message},#{options})"
end

- (::Vertx::MessageProducer) sender(address = nil, options = nil)

Like #sender but specifying delivery options that will be used for configuring the delivery of the message.

Parameters:

  • address (String) (defaults to: nil)
    the address to send it to
  • options (Hash) (defaults to: nil)
    the delivery options

Returns:

Raises:

  • (ArgumentError)

136
137
138
139
140
141
142
143
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/event_bus.rb', line 136

def sender(address=nil,options=nil)
  if address.class == String && !block_given? && options == nil
    return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:sender, [Java::java.lang.String.java_class]).call(address),::Vertx::MessageProducer, nil)
  elsif address.class == String && options.class == Hash && !block_given?
    return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:sender, [Java::java.lang.String.java_class,Java::IoVertxCoreEventbus::DeliveryOptions.java_class]).call(address,Java::IoVertxCoreEventbus::DeliveryOptions.new(::Vertx::Util::Utils.to_json_object(options))),::Vertx::MessageProducer, nil)
  end
  raise ArgumentError, "Invalid arguments when calling sender(#{address},#{options})"
end