Message

Undocumented in source.

Members

Functions

createResponse
Message createResponse(T payload)
Undocumented in source. Be warned that the author may not have intended to support it.
createResponse
Message createResponse(ResponseStatus responseStatus, T payload)
Undocumented in source. Be warned that the author may not have intended to support it.
setToExpireAfter
void setToExpireAfter(Duration duration)
Undocumented in source. Be warned that the author may not have intended to support it.
to
T to()
Undocumented in source. Be warned that the author may not have intended to support it.
toJSON
JSON toJSON()
Undocumented in source. Be warned that the author may not have intended to support it.
toString
string toString()
Undocumented in source. Be warned that the author may not have intended to support it.

Properties

hasExpired
bool hasExpired [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
isEmpty
bool isEmpty [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.

Static functions

from
Message from(T payload)
Undocumented in source. Be warned that the author may not have intended to support it.
from
Message from(T payload, string token)
Undocumented in source. Be warned that the author may not have intended to support it.
from
Message from(T payload, UUID correlationId)
Undocumented in source. Be warned that the author may not have intended to support it.
from
Message from(T payload, string token, UUID correlationId)
Undocumented in source. Be warned that the author may not have intended to support it.
opCall
Message opCall()
Undocumented in source. Be warned that the author may not have intended to support it.

Variables

correlationId
UUID correlationId;
Undocumented in source.
created
SysTime created;
Undocumented in source.
expires
SysTime expires;
Undocumented in source.
payload
BSON payload;
Undocumented in source.
replyToQueueName
string replyToQueueName;
Undocumented in source.
responseStatus
ResponseStatus responseStatus;
Undocumented in source.
token
string token;
Undocumented in source.
type
string type;
Undocumented in source.

Examples

Message#from/to

struct Page {
  string title;
  string body;
}

auto expectedOutput = Page("A title", "Lorem ipsum dolor sit amet, consectetur...");

auto message = Message.from(expectedOutput);
auto output = message.to!Page();

assert(output.title == expectedOutput.title, "Expected title to match");
assert(output.body == expectedOutput.body, "Expected body to match");

Message#to - bad type

struct Page {
  string title;
  string body;
}

struct Author {
  string name;
}

auto expectedOutput = Page("A title", "Lorem ipsum dolor sit amet, consectetur...");

auto message = Message.from(expectedOutput);

TypeMismatchException gotException;
try {
  auto output = message.to!Author();
} catch (TypeMismatchException exception) {
  gotException = exception;
}

assert(gotException.msg == "Expected type Author but got Page");

Message#createResponse - verify that response status is set

import std.conv : to;

struct Ping {
  string message;
}

auto ping = Ping("Lorem ipsum...");
auto request = Message.from(ping);
auto response = request.createResponse(ResponseForbidden());

assert(response.type == "ResponseForbidden",
    "Expected response.type to equal ResponseForbidden, got " ~ response.type);
assert(response.responseStatus == ResponseStatus.FORBIDDEN,
    "Expected responseStatus to be ResponseStatus.FORBIDDEN got "
    ~ response.responseStatus.to!string);
assert(response.correlationId == request.correlationId,
    "response.correlationId should equal request.correlationId");

Meta