Class List Method List File List

# Class: Vertx::Message

Inherits:
  Object
  - Object
  - Vertx::Message
  show all
Defined in:
  /Users/julien/java/vertx-stack/stack-docs/target/rb/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.
- - (true, false) send?
  Signals if this message represents a send or publish event.

## Instance Method Details

### - (`String`) address

The address the message was sent to

Returns:

- (`String`)

Raises:

- (`ArgumentError`)

    27
    28
    29
    30
    31
    32
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/message.rb', line 27

    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`)

    43
    44
    45
    46
    47
    48
    49
    50
    51
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/message.rb', line 43

    def body
      if !block_given?
        if @cached_body != nil
          return @cached_body
        end
        return @cached_body = @j_arg_T.wrap(@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`)

    93
    94
    95
    96
    97
    98
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/message.rb', line 93

    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`)

    35
    36
    37
    38
    39
    40
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/message.rb', line 35

    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`)

    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/message.rb', line 74

    def reply(message=nil,options=nil)
      if ::Vertx::Util::unknown_type.accept?(message) && !block_given? && options == nil
        return @j_del.java_method(:reply, [Java::java.lang.Object.java_class]).call(::Vertx::Util::Utils.to_object(message))
      elsif ::Vertx::Util::unknown_type.accept?(message) && 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) : nil) }))
      elsif ::Vertx::Util::unknown_type.accept?(message) && 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 ::Vertx::Util::unknown_type.accept?(message) && 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) : 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`)

    54
    55
    56
    57
    58
    59
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/message.rb', line 54

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

### - (`true`, `false`) send?

Signals if this message represents a send or publish event.

Returns:

- (`true`, `false`) —
  true if this is a send.

Raises:

- (`ArgumentError`)

    62
    63
    64
    65
    66
    67
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/message.rb', line 62

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