Zero system support five request modes as following ( Please ignore the name of the mode, it's for distinguish differences only )
This mode is used for request response mode in vert.x, you can define your method as following:
@GET
@Path("/sync/string")
public String syncRequest(
@QueryParam("email") final String email
) {
final String response = "Testing finished";
return response;
}
Rule:
- The return type of method type mustn't be
void
; - Do not use
@Address
annotation on this method;
Workflow
This mode is used for request only mode in vert.x, you cand define your method as following:
@GET
@Path("/block/{name}")
public void blockRequest(
@PathParam("name") final String name) {
System.out.println("block request");
}
Rule
- The return type of method must be
void
; - Do not want to get any data from response, this kind of mode only provide status of this job
Workflow
This mode is samiliar with Mode2, but the data will send to event bus to execute async jobs. ( Will be removed )
Sender
@POST
@Path("/one-way/user")
@Address("ZERO://USER")
public String sendNotify(
@BodyParam final User user) {
final String response = Jackson.serialize(user);
return response;
}
Consumer
@Address("ZERO://USER")
public void reply(final Envelop message) {
final User user = message.data(User.class);
// Do somethings
}
Rule
- The methods of
@EndPoint
and@Queue
must be annotated with@Address
and they are the same between sender and consumer - The return type of method in
@EndPoint
mustn't bevoid
- You must be define the consumer method signature to
public void xxx(Envelop)
Workflow
This mode is async request response mode between consumer and sender on event bus.
Sender
@POST
@Path("/async/user")
@Address("ZERO://ROLE")
public String sendAsync(
@BodyParam final User user) {
final String response = Jackson.serialize(user);
return response;
}
Consumer
@Address("ZERO://USER")
public Envelop reply(final Envelop message) {
final User user = message.data(User.class);
final WebException error = new TestRequestException(getClass(),
"Lang", "Detail");
return Envelop.failure(error);
}
Rule
- The methods of
@EndPoint
and@Queue
must be annotated with@Address
and they are the same between sender and consumer - The return type of method in
@EndPoint
mustn't bevoid
- You must be define the consumer method signature to
public Envelop xxx(Envelop)
Workflow
This mode is supported for some vert.x component use in service layer of the system such as MongoClient, SQLClient etc.
Sender ( The same as mode 4 )
@Path("/event")
@POST
@Address("ZERO://EVENT")
public JsonObject sayEvent(
@BodyParam final JsonObject data) {
return data;
}
Consumer
@Mongo
private transient MongoClient client;
@Address("ZERO://ROLE")
public void async(final Message<Envelop> message) {
final User user = Envelop.data(message, User.class);
final JsonObject userData = new JsonObject(Jackson.serialize(user));
this.client.save("DB_USER", userData, res -> {
if (res.succeeded()) {
message.reply(Envelop.success("Hello World"));
} else {
res.cause().printStackTrace();
}
});
}
Rule
- The methods of
@EndPoint
and@Queue
must be annotated with@Address
and they are the same between sender and consumer - The return type of method in
@EndPoint
mustn't bevoid
- You must be define the consumer method signature to
public void xxx(Message<Envelop>)
- Don't forget call
reply(Envelop
in call back onMessage<Envelop>
Workflow
All above request mode could describe different usage, but we recomment to use Mode 4 & Mode 5.