RouteBuilder from exposing as a ChoiceDefinition rather than a RouteDefinition

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

RouteBuilder from exposing as a ChoiceDefinition rather than a RouteDefinition

peter.berkman
This post was updated on .
Please help  I have no idea what I'm doing wrong here!:

camel 2.12.0
jdk 1.6
Karath 2.3.3

[ERROR] HL7MapRouteBuilder.java:[94,8] incompatible types
found   : org.apache.camel.model.ChoiceDefinition
required: org.apache.camel.model.RouteDefinition
[INFO] 1 error

Code from the configure() method:

		route = from(NGMSConstants.QUEUE_PREFIX + HL7MapGroup.QUEUE_IN).routePolicy(throttlePolicy).id(routeName)
	    			.process(preMapHook).id("pre-map-hook")
	    			.choice().id("check-route-trigger")
	    				.when(header(NGMSConstants.ROUTING_TRIGGER).contains("HL7v2_ADT"))
	    					.bean(adtToMMFeed, "map")
	    					.endChoice()

	    				.when(header(NGMSConstants.ROUTING_TRIGGER).contains("HL7v2_ORU")).id("ORU-map-choice")
	    					.bean(HL7v2MapFactory.getORUORMv231toMMFeed(), "map").id("map-ORU")
	    					.endChoice()
	    					
	    	    	    .when(header(NGMSConstants.ROUTING_TRIGGER).contains("HL7v2_ORM")).id("ORM-map-choice")
	    	    	    	.bean(HL7v2MapFactory.getORUORMv231toMMFeed(), "map").id("map-ORM")
	    	    	    	.endChoice()
	    	    	    	
	    	    		.when(header(NGMSConstants.ROUTING_TRIGGER).contains("HL7v2_QBP_Q22")).id("QBPQ22-map-choice")
	    	    			.bean(HL7v2MapFactory.getQBP_Q22toMMQuery(), "map").id("map-QBPQ22")
	    	    			.endChoice()
	    	    			
	    	    	    .when(header(NGMSConstants.ROUTING_TRIGGER).contains("HL7v2_QBP_Q23")).id("QBPQ23-map-choice")
	    	    	    	.bean(HL7v2MapFactory.getQBP_Q23toMMQuery(), "map").id("map-QBPQ23")
	    	    	    	.endChoice()
	    	    	    	
	    	    	    .when(header(NGMSConstants.ROUTING_TRIGGER).contains("HL7v2_QCN_J01")).id("QCNJ01-map-choice")
	    	    	    	.bean(HL7v2MapFactory.getQCN_J01toACK(), "map").id("map-QCNJ01")
	    	    	    	.endChoice()
	    	    	    	
	    	    	    .otherwise().id("otherwise")
	    	    	    	.bean(com.nextgate.ms.component.mapper.hl7v2.ANYtoNAK.class).id("map-NAK")
	    	    	    	.endChoice()
	    	    	    	
	    	    	.process(HooksFactory.getPostMapHook()).id("post-map-hook")
	  .to("mock:result");

I've also tried a simpler route - same behavior.  Does the .choice even work in Java DSL?

		route = from(NGMSConstants.QUEUE_PREFIX + HL7MapGroup.QUEUE_IN).routeId(routeName).routePolicy(throttlePolicy)
				
	    			.process(HooksFactory.getPreMapHook()).id("pre-map-hook")
	    			
	    			.choice().id("check-route-trigger")
	    			
	    				.when(header(NGMSConstants.ROUTING_TRIGGER).contains("HL7v2_ADT")).id("ADT-map-choice")
	    					.to("direct:ngmsADTmap")

	    				.when(header(NGMSConstants.ROUTING_TRIGGER).contains("HL7v2_ORU")).id("ORU-map-choice")
	    					.to("direct:ngmsORUmap")
	    					
	    				.otherwise()
	    					.to("direct:ngmsNAKmap")
   					.endChoice()
	    			
	    			.process(JournallerFactory.getJournaller())
	    			.process(HooksFactory.getPreSendHook())
	    			.process(TrackerFactory.getRecv())
	    		.to("direct:test");
Reply | Threaded
Open this post in threaded view
|

Re: RouteBuilder from exposing as a ChoiceDefinition rather than a RouteDefinition

Claus Ibsen-2
Try with just end()

endChoice() is for special work-around use-cases
http://camel.apache.org/why-can-i-not-use-when-or-otherwise-in-a-java-camel-route.html

On Fri, Nov 15, 2013 at 12:30 AM, peter.berkman
<[hidden email]> wrote:

> Please help  I have no idea what I'm doing wrong here!:
>
>
>
> Code from the configure() method:
>
>
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/RouteBuilder-from-exposing-as-a-ChoiceDefinition-rather-than-a-RouteDefinition-tp5743309.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: [hidden email]
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Reply | Threaded
Open this post in threaded view
|

Re: RouteBuilder from exposing as a ChoiceDefinition rather than a RouteDefinition

peter.berkman
In reply to this post by peter.berkman
I've tried that -- on the simple case just replacing endChoice() with end().  same issue there, and depending where I put it, it changes what it thinks it is from a ChoiceDefinition to a ProcessorDefinition.

I've also tried using .filter.  However, that forces 'from' to expose yet a different object which is also incompatible with a RouteDefinition...  HELP!!

this seems very broken - is it not used much?  we started with Spring routes, but ran into a number of restrictions - especially in OSGi that we could not live with, so we decided to go with Java DSL mainly because from everything I've read, it seemed to be what most are using.  However, if you can't use choice or filter, it seems fairly useless, no?

let me know what the plan is for this and if I should be looking into a different DSL to use ...

thanks Claus, always appreciate your quick help!
Reply | Threaded
Open this post in threaded view
|

Re: RouteBuilder from exposing as a ChoiceDefinition rather than a RouteDefinition

peter.berkman
In reply to this post by peter.berkman
finally figured it out.

first, because a ChoiceDefinition will compile just fine, but throw an exception at runtime, set the "from" to a local RouteDefinition variable - this way, the editor/compiler will complain.

    	RouteDefinition route;
...

		route = (RouteDefinition) from(NGMSConstants.QUEUE_PREFIX + HL7MapGroup.QUEUE_IN).routeId(routeName).routePolicy(throttlePolicy)

(note: the cast is needed because when you use ".end()" or ".filter()" it returns a ProcessorDefinition or "Capture" - both of which *can* be cast to a RouteDefinition)

a couple of rules I found about ".choice":

1) only use ".endChoice()" after a ".multicast()" (or other complex pattern) that is within a ".when()" or at the end of an ".otherwise()".

2) use ".end()" at the final end of the ".choice()"

here is my final complicated example from the original question that works:

		route = (RouteDefinition) from(NGMSConstants.QUEUE_PREFIX + HL7MapGroup.QUEUE_IN).routeId(routeName).routePolicy(throttlePolicy)
				
	    		.process(HooksFactory.getPreMapHook()).id("pre-map-hook")

				.choice().id("check-route-trigger")
					
					.when(header(NGMSConstants.ROUTING_TRIGGER).contains("HL7v2_ADT")).id("ADT-map-choice")
						
						.bean(HL7v2MapFactory.getADTtoMMFeed(), "map").id("map-ADT")
				
					.when(header(NGMSConstants.ROUTING_TRIGGER).contains("HL7v2_ORU")).id("ORU-map-choice")
						
						.bean(HL7v2MapFactory.getORUORMv231toMMFeed(), "map").id("map-ORU")
							
			               .when(header(NGMSConstants.ROUTING_TRIGGER).contains("HL7v2_ORM")).id("ORM-map-choice")
					    
					    .bean(HL7v2MapFactory.getORUORMv231toMMFeed(), "map").id("map-ORM")
					    	
					.when(header(NGMSConstants.ROUTING_TRIGGER).contains("HL7v2_QBP_Q22")).id("QBPQ22-map-choice")
						
						.bean(HL7v2MapFactory.getQBP_Q22toMMQuery(), "map").id("map-QBPQ22")
							
					.when(header(NGMSConstants.ROUTING_TRIGGER).contains("HL7v2_QBP_Q23")).id("QBPQ23-map-choice")
					    
					    .bean(HL7v2MapFactory.getQBP_Q23toMMQuery(), "map").id("map-QBPQ23")
					    	
					.when(header(NGMSConstants.ROUTING_TRIGGER).contains("HL7v2_QCN_J01")).id("QCNJ01-map-choice")
					    
					    .bean(HL7v2MapFactory.getQCN_J01toACK(), "map").id("map-QCNJ01")
					    	
					.otherwise().id("otherwise")
					    
					    	.bean(com.nextgate.ms.component.mapper.hl7v2.ANYtoNAK.class).id("map-NAK")
					    	.endChoice()
					    	
			 .end()
				    	
	    	    	.process(HooksFactory.getPostMapHook()).id("post-map-hook")

	    	    	.choice().id("determine-destination")
	    	    	
	    	    		.when(header(NGMSConstants.ROUTING_TRIGGER).isEqualTo(NGMSMMConstants.ROUTING_TRIGGER_REGISTRATIONFEED)).id("registration-feed")
	    	    		
	    	    			.bean(MMAdapterFactory.getRegistrationFeed(), "exec").id("exec-mm-registration-processing")
	    	    			.process(HooksFactory.getPostAdapterHook()).id("post-adapter-hook")
	    	    			
	    	    			.multicast().parallelProcessing().onPrepare(CoreFactory.getCloneProcessor()).id("multicast-reg-feed")
	    	    				.inOnly(AuditFactory.AUDITCHK_URI).id("check-audit")
	    	    				.inOnly(ENRICH_PREURI).id("enrichment-route")
	    	    				.bean(HL7v2MapFactory.getANYtoACK(), "map").id("map-ack")
	    	    			.endChoice()
    	    			
	    	    		.when(header(NGMSConstants.ROUTING_TRIGGER).isEqualTo(NGMSMMConstants.ROUTING_TRIGGER_ORDERFEED)).id("order-feed")
	    	    		
	    	    			.bean(MMAdapterFactory.getOrderFeed(), "exec").id("exec-mm-order-processing")
	    	    			.process(HooksFactory.getPostAdapterHook()).id("post-adapter-hook")
	    	    			
	    	    			.multicast().parallelProcessing().onPrepare(CoreFactory.getCloneProcessor()).id("multicast-order-feed")
	    	    				.inOnly(AuditFactory.AUDITCHK_URI).id("check-audit")
	    	    				.inOnly(ENRICH_PREURI).id("enrichment-route")
	    	    				.bean(HL7v2MapFactory.getANYtoACK(), "map").id("map-ack")
	    	    			.endChoice()
	    	    			
	    	    		.when(header(NGMSConstants.ROUTING_TRIGGER).isEqualTo(NGMSMMConstants.ROUTING_TRIGGER_PROVIDERFEED)).id("provider-feed")
	    	    		
	    	    			.bean(MMAdapterFactory.getProviderFeed(), "exec").id("exec-mm-provider-feed")
	    	    			.process(HooksFactory.getPostAdapterHook()).id("post-adapter-hook")
	    	    			
	    	    			.multicast().parallelProcessing().onPrepare(CoreFactory.getCloneProcessor()).id("multicast-prov-feed")
	    	    				.inOnly(AuditFactory.AUDITCHK_URI).id("check-audit")
	    	    				.inOnly(ENRICH_PREURI).id("enrichment-route")
	    	    				.bean(HL7v2MapFactory.getMMFeedtoACK(), "map").id("map-ack")
	    	    			.endChoice()
	    	    			
	    	    		.when(header(NGMSConstants.ROUTING_TRIGGER).isEqualTo(NGMSMMConstants.ROUTING_TRIGGER_QUERY)).id("person-query")
	    	    		
	    	    			.bean(MMAdapterFactory.getPersonQuery(), "exec").id("exec-mm-person-query")
	    	    			.process(HooksFactory.getPostAdapterHook()).id("post-adapter-hook")
	    	    			
	    	    			.multicast().parallelProcessing().onPrepare(CoreFactory.getCloneProcessor()).id("multicast-pers-query")
	    	    				.inOnly(AuditFactory.AUDITCHK_URI).id("check-audit")
	    	    				.bean(HL7v2MapFactory.getMMQuerytoRSP(), "map").id("map-query-response")
	    	    			.endChoice()

	    	    	.end()
	    	    		
			.process(JournallerFactory.getJournaller()).id("journal-outbound")
			.process(HooksFactory.getPreSendHook()).id("pre-send-hook")
			.process(TrackerFactory.getSend()).id("track send")
					
			.marshal(hl7).id("marshal-result");

 Thank you Claus for ultimately pointing me in the right direction!!!