Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Child pages (Children Display)

Receive asynchronous message

Receive asynchronous messages and storing them to DB:

  • all essential things are solved in AsynchInMessageRoute (trace header recognition, create message, persist to DB, exception handling)
  • use AsynchRouteBuilder to implement inbound asynchronous message

 

Code Block
languagejava
    /**
     * Route for asynchronous <strong>asyncHello</strong> input operation.
     * <p/>
     * Prerequisite: none
     * <p/>
     * Output: {@link AsyncHelloResponse}
     */
    private void createRouteForAsyncHelloRouteIn() throws FailedToCreateRouteException {
        Namespaces ns = new Namespaces("h", SyncHelloRoute.HELLO_SERVICE_NS);
   
        // note: mandatory parameters are set already in XSD, this validation is extra
        XPathValidator validator1 = new XPathValidator("/h:asyncHelloRequest", ns, "h:name1");
 
        // note: mandatory parameters are set already in XSD, this validation is extra
        XPathValidator validator2 = new XPathValidator("/h:asyncHelloRequest", ns, "h:name2");
   
        // note: only shows using but without any influence in this case
        Expression nameExpr = xpath("/h:asyncHelloRequest/h:name").namespaces(ns).stringResult();
  
        AsynchRouteBuilder.newInstance(ServiceEnum.HELLO, OPERATION_NAME,
                getInWsUri(new QName(SyncHelloRoute.HELLO_SERVICE_NS, "asyncHelloRequest")),
                new AsynchResponseProcessor() {
                    @Override
                    protected Object setCallbackResponse(CallbackResponse callbackResponse) {
                        AsyncHelloResponse res = new AsyncHelloResponse();
                        res.setConfirmAsyncHello(callbackResponse);
                        return res;
                    }
                }, jaxb(AsyncHelloResponse.class))
                .withValidator(validator1, validator2)
                .withObjectIdExpr(nameExpr)
                .build(this);
    }
 
AsynchRouteBuilder creates uniform design of asynchronous routes (processes) with the following processing steps (low-level approach):
  • settings the name of source service and operation. This information (based name conventions) are necessary to resolving of start endpoint to process asynchronous part.
  • execution of general validation (check required values). If a validation error occurs then OpenHub framework will throw ValidationIntegrationException or org.apache.camel.ValidationException (from Apache Camel).
  • redirection to "to(AsynchConstants.URI_ASYNCH_IN_MSG)"
  • using AsynchResponseProcessor - checking whether created message was successfully persisted or some error did not occur, after that correct response will be produced.

Hereby accepting an asynchronous message ends, is persisted in internal database for further processing and OpenHub framework sends confirmation to external system that message was adopted.

...