Sending data
The previous microservice handler was very contrived. It is more likely that microservice handlers will be implemented to perform some processing on data and return some value. In a normal HTTP handler, we would use @Req
or @Body
to extract the data from the HTTP request’s body. Since microservice handlers have no HTTP context, they take input data as a method parameter.
@
Controller
()
export
class
UserController
{
@
Client
({
transport
:Transport.TCP
,
options
:
{
port
:5667
}})
client
:ClientProxy
@
Post
(
'users'
)
public
async
create
(
@
Req
()
req
,
@
Res
()
res
)
{
this
.
client
.
send
({
cmd
:
'users.index'
},
{}).
subscribe
({
next
:users
=>
{
res
.
status
(
HttpStatus
.
OK
).
json
(
users
);
},
error
:error
=>
{
res
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
json
(
error
);
}
});
}
@
MessagePattern
({
cmd
:
'users.create'
})
public
async
rpcCreate...