Class List Method List File List

# Class: Vertx::Message

Inherits:
  Object
  - Object
  - Vertx::Message
  show all
Defined in:
  /Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/message.rb

## Overview

Represents a message that is received from the event bus in a handler.

Messages have a #body, which can be null, and also #headers, which can be empty.

If the message was sent specifying a reply handler it will also have a #reply_address. In that case the message can be replied to using that reply address, or, more simply by just using #reply.

If you want to notify the sender that processing failed, then #fail can be called.

## Instance Method Summary (collapse)

- - (String) address
  The address the message was sent to.
- - (Object) body
  The body of the message.
- - (void) fail(failureCode = nil, message = nil)
  Signal to the sender that processing of this message failed.
- - (::Vertx::MultiMap) headers
  Multi-map of message headers.
- - (void) reply(message = nil, options = nil) { ... }
  The same as reply(R message, DeliveryOptions) but you can specify handler for the reply - i.e.
- - (String) reply_address
  The reply address.

## Instance Method Details

### - (`String`) address

The address the message was sent to

Returns:

- (`String`)

Raises:

- (`ArgumentError`)

    26
    27
    28
    29
    30
    31
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/message.rb', line 26

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

### - (`Object`) body

The body of the message. Can be null.

Returns:

- (`Object`) —
  the body, or null.

Raises:

- (`ArgumentError`)

    42
    43
    44
    45
    46
    47
    48
    49
    50
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/message.rb', line 42

    def body
      if !block_given?
        if @cached_body != nil
          return @cached_body
        end
        return @cached_body = ::Vertx::Util::Utils.from_object(@j_del.java_method(:body, []).call())
      end
      raise ArgumentError, "Invalid arguments when calling body()"
    end

### - (`void`) fail(failureCode = nil, message = nil)

This method returns an undefined value.

Signal to the sender that processing of this message failed.

If the message was sent specifying a result handler the handler will be called with a failure corresponding to the failure code and message specified here.

Parameters:

- failureCode (`Fixnum`) (defaults to: `nil`) —
  A failure code to pass back to the sender
- message (`String`) (defaults to: `nil`) —
  A message to pass back to the sender

Raises:

- (`ArgumentError`)

    84
    85
    86
    87
    88
    89
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/message.rb', line 84

    def fail(failureCode=nil,message=nil)
      if failureCode.class == Fixnum && message.class == String && !block_given?
        return @j_del.java_method(:fail, [Java::int.java_class,Java::java.lang.String.java_class]).call(failureCode,message)
      end
      raise ArgumentError, "Invalid arguments when calling fail(failureCode,message)"
    end

### - (`::Vertx::MultiMap`) headers

Multi-map of message headers. Can be empty

Returns:

- (`::Vertx::MultiMap`) —
  the headers

Raises:

- (`ArgumentError`)

    34
    35
    36
    37
    38
    39
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/message.rb', line 34

    def headers
      if !block_given?
        return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:headers, []).call(),::Vertx::MultiMap)
      end
      raise ArgumentError, "Invalid arguments when calling headers()"
    end

### - (`void`) reply(message = nil, options = nil) { ... }

This method returns an undefined value.

The same as `reply(R message, DeliveryOptions)` but you can specify handler for the reply - i.e. to receive the reply to the reply.

Parameters:

- message (`Object`) (defaults to: `nil`) —
  the reply message
- options (`Hash`) (defaults to: `nil`) —
  the delivery options

Yields:

- the reply handler for the reply.

Raises:

- (`ArgumentError`)

    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/message.rb', line 65

    def reply(message=nil,options=nil)
      if (message.class == String  || message.class == Hash || message.class == Array || message.class == NilClass || message.class == TrueClass || message.class == FalseClass || message.class == Fixnum || message.class == Float) && !block_given? && options == nil
        return @j_del.java_method(:reply, [Java::java.lang.Object.java_class]).call(::Vertx::Util::Utils.to_object(message))
      elsif (message.class == String  || message.class == Hash || message.class == Array || message.class == NilClass || message.class == TrueClass || message.class == FalseClass || message.class == Fixnum || message.class == Float) && block_given? && options == nil
        return @j_del.java_method(:reply, [Java::java.lang.Object.java_class,Java::IoVertxCore::Handler.java_class]).call(::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) }))
      elsif (message.class == String  || message.class == Hash || message.class == Array || message.class == NilClass || message.class == TrueClass || message.class == FalseClass || message.class == Fixnum || message.class == Float) && options.class == Hash && !block_given?
        return @j_del.java_method(:reply, [Java::java.lang.Object.java_class,Java::IoVertxCoreEventbus::DeliveryOptions.java_class]).call(::Vertx::Util::Utils.to_object(message),Java::IoVertxCoreEventbus::DeliveryOptions.new(::Vertx::Util::Utils.to_json_object(options)))
      elsif (message.class == String  || message.class == Hash || message.class == Array || message.class == NilClass || message.class == TrueClass || message.class == FalseClass || message.class == Fixnum || message.class == Float) && options.class == Hash && block_given?
        return @j_del.java_method(:reply, [Java::java.lang.Object.java_class,Java::IoVertxCoreEventbus::DeliveryOptions.java_class,Java::IoVertxCore::Handler.java_class]).call(::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) }))
      end
      raise ArgumentError, "Invalid arguments when calling reply(message,options)"
    end

### - (`String`) reply_address

The reply address. Can be null.

Returns:

- (`String`) —
  the reply address, or null, if message was sent without a reply handler.

Raises:

- (`ArgumentError`)

    53
    54
    55
    56
    57
    58
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/message.rb', line 53

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