Axon 3.1:QueryBus/QueryGateway

442 views
Skip to first unread message

Peter Brantschen

unread,
Dec 11, 2017, 9:18:42 AM12/11/17
to Axon Framework Users
Hi

Is there somewhere a code-example about the new query bus, query gateway? An example of best practice?

Regards,
Peter

Oscar Scholten

unread,
Dec 12, 2017, 3:37:44 AM12/12/17
to axonfr...@googlegroups.com
Hi Peter,

Assuming you are using Spring in your application, the Axon AutoConfigurer creates a QueryGateway and SimpleQueryBus.

A small example would be:

@RestController
public class MyQueryController {

    @Autowired
    private QueryGateway queryGateway;

    @GetMapping("/query")
    public ResponseEntity doQuery() throws Exception {
        CompletableFuture<MyResult> future = queryGateway.send(new MyQuery(), MyResult.class);
        // possibly do some more work
        MyResult result = future.get();
        return new ResponseEntity<>(result, HttpStatus.CREATED);
    }
}

@Component
public class MyQueryHandler {

    @QueryHandler
    public MyResult handle(MyQuery query) {
        return new MyResult();
    }
}

Hope this helps, Oscar

--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframework+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages