jina.types.message

class jina.types.message.Message(envelope, request, *args, **kwargs)[source]

Bases: object

Message is one of the primitive data type in Jina.

It offers a Pythonic interface to allow users access and manipulate jina.jina_pb2.MessageProto object without working with Protobuf itself.

A container class for jina_pb2.MessageProto. Note, the Protobuf version of jina_pb2.MessageProto contains a jina_pb2.EnvelopeProto and jina_pb2.RequestProto. Here, it contains:

  • a jina_pb2.EnvelopeProto object

  • and one of:
    • a Request object wrapping jina_pb2.RequestProto

    • a jina_pb2.RequestProto object

It provide a generic view of as jina_pb2.MessageProto, allowing one to access its member, request and envelope as if using jina_pb2.MessageProto object directly.

This class also collected all helper functions related to jina_pb2.MessageProto into one place.

property as_pb_object
Return type

MessageProto

property is_data_request

check if the request is not a control request

Warning

If request change the type, e.g. by leveraging the feature of oneof, this property wont be updated. This is not considered as a good practice.

Return type

bool

dump()[source]
Return type

List[bytes]

property colored_route

Get the string representation of the routes in a message.

Return type

str

Returns

add_route(name, identity)[source]
property size

Get the size in bytes.

To get the latest size, use it after dump()

update_timestamp()[source]

Update the timestamp of the last route

property response

Get the response of the message in protobuf.

Note

This should be only called at Gateway

Return type

Request

merge_envelope_from(msgs)[source]
add_exception(ex=None, executor=None)[source]

Add exception to the last route in the envelope

Parameters

ex (Optional[ForwardRef]) – Exception to be added

Return type

None

Returns

property is_error
Return type

bool

property is_ready
Return type

bool