Source:
public static void main(String[] args) throws ScriptException, FileNotFoundException, NoSuchMethodException { MsbContext msbContext = new MsbContextBuilder() .enableChannelMonitorAgent(true) .enableShutdownHook(true) .build(); MessageTemplate options = new MessageTemplate(); final String namespace = "search:aggregator:facets:v1"; msbContext.getObjectFactory().createResponderServer(namespace, options, (request, responder) -> { RequestQuery query = request.getQueryAs(RequestQuery.class); String q = query.getQ(); if (q == null) { Payload responsePayload = new Payload.Builder() .withStatusCode(400) .build(); responder.send(responsePayload); } else if (q.isEmpty()) { ResponseBodyAny responseBodyAny = new ResponseBodyAny(); Facet facet = new Facet(); facet.setProbability(1f); Map<String, Object> map = new HashMap<>(); map.put("depAirport", 0); map.put("resortCode", "any"); facet.setParams(map); responseBodyAny.setFacets(Arrays.asList(facet)); Payload responsePayloadAny = new Payload.Builder() .withStatusCode(200) .withBody(responseBodyAny).build(); responder.send(responsePayloadAny); } else { RequestOptions requestOptions = new RequestOptions.Builder() .withWaitForResponses(1) .withAckTimeout(200) .withResponseTimeout(600) .build(); Requester requester = msbContext.getObjectFactory().createRequester("search:parsers:facets:v1", requestOptions); final String[] result = {""}; requester.onResponse(response -> { System.out.println(">>> RESPONSE: " + response); result[0] +=response; }); requester.onEnd(listOfMessages -> { for (Message message : listOfMessages) System.out.println(">>> MESSAGE: " + message.getPayload().getBody()); Payload responsePayload = new Payload.Builder() .withStatusCode(200) .withBody(result[0]).build(); responder.send(responsePayload); }); requester.publish(request, responder.getOriginalMessage().getCorrelationId()); } }).listen(); }

Target:
public static void main(String[] args) throws ScriptException, FileNotFoundException, NoSuchMethodException { MsbContext msbContext = new MsbContextBuilder() .enableChannelMonitorAgent(true) .enableShutdownHook(true) .build(); MessageTemplate options = new MessageTemplate(); final String namespace = "search:aggregator:facets:v1"; msbContext.getObjectFactory().createResponderServer(namespace, options, (request, responder) -> { RequestQuery query = request.getQueryAs(RequestQuery.class); String q = query.getQ(); if (q == null) { Payload responsePayload = new Payload.Builder() .withStatusCode(400) .build(); responder.send(responsePayload); } else if (q.isEmpty()) { ResponseBodyAny responseBodyAny = new ResponseBodyAny(); Facet facet = new Facet(); facet.setProbability(1f); Map<String, Object> map = new HashMap<>(); map.put("depAirport", 0); map.put("resortCode", "any"); facet.setParams(map); responseBodyAny.setFacets(Arrays.asList(facet)); Payload responsePayloadAny = new Payload.Builder() .withStatusCode(200) .withBody(responseBodyAny).build(); responder.send(responsePayloadAny); } else { RequestOptions requestOptions = new RequestOptions.Builder() .withWaitForResponses(1) .withAckTimeout(200) .withResponseTimeout(600) .build(); Requester requester = msbContext.getObjectFactory().createRequester("search:parsers:facets:v1", requestOptions); final String[] result = {""}; requester.onResponse(response -> { System.out.println(">>> RESPONSE: " + response); result[0] +=response; }); requester.onEnd(listOfMessages -> { for (Message message : listOfMessages) System.out.println(">>> MESSAGE: " + message.getPayload().getBody()); Payload responsePayload = new Payload.Builder() .withStatusCode(200) .withBody(result[0]).build(); responder.send(responsePayload); }); requester.publish(request, responder.getOriginalMessage()); } }).listen(); }