You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by MohamedAli <tr...@gmail.com> on 2014/01/23 07:53:59 UTC

Camel Bindy with multiple model and multiple RouteBuilder

Hello,
I have tried to send message string to single model and single routebuilder
it works fine!!!
I have List of String which is sent to bindy to convert into POJO from
multiple model with multiple routebuilder, but it not not working.
Please find the sample below and guilde to fix the issue.

*camel-context.xml*
<camel:camelContext id="camelContextBean" trace="true"
lazyLoadTypeConverters="false"
		autoStartup="false">
   		<camel:routeBuilder id="tripStartBuilder" ref="tripStartBuilder"/>
   		<camel:routeBuilder id="pivotBuilder" ref="pivotBuilder" />
	</camel:camelContext>

	<bean id="pivotBuilder"
class="com.smart.listener.message.builder.PivotBuilder" />
	<bean id="tripStartBuilder"
class="com.smart.listener.message.builder.TripStartBuilder" />

*PivotBuilder extends RouteBuilder*
        @Override
	public void configure() throws Exception {
		DataFormat bindy = new BindyCsvDataFormat(LocationPivot.class);
		
		System.out.println("PivotBuilder..."	);
		from("direct:location").unmarshal(bindy).process(new Processor() {

			public void process(Exchange exchange) throws Exception {
				Message in = exchange.getIn();
				/*List<Map&lt;String, Object>> model = (List<Map&lt;String, Object>>) in
						.getBody();*/
				LocationPivot locPvt = (LocationPivot)in.getBody();
				//BasicMsgPivot locPvt =
(BasicMsgPivot)model.get(0).values().toArray()[0];
				System.out.println(locPvt.getMsgInd());
				System.out.println(locPvt.getImeiNo());

			}
		});
	}

*TripStartBuilder extends RouteBuilder*
@Override
	public void configure() throws Exception {
		DataFormat bindy = new BindyCsvDataFormat(TripStartPivot.class);
		
		System.out.println("TripStartBuilder...");
		from("direct:trip").unmarshal(bindy).process(new Processor() {

			public void process(Exchange exchange) throws Exception {
				Message in = exchange.getIn();
				/*List<Map&lt;String, Object>> model = (List<Map&lt;String, Object>>) in
						.getBody();*/
				//BasicMsgPivot locPvt =
(BasicMsgPivot)model.get(0).values().toArray()[0];
				TripStartPivot trPvt = (TripStartPivot)in.getBody();
				System.out.println(trPvt.getMsgInd());
				System.out.println(trPvt.getImeiNo());

			}
		});

*@CsvRecord(separator = ",")
public class LocationPivot extends BasicMsgPivot {*

	@DataField(pos = 1)
	private String msgInd;

	@DataField(pos = 2)
	private BigDecimal imeiNo;

	@DataField(pos=3, pattern="ddMMyy")
	private Date currDate;

*@CsvRecord(separator = ",")
public class TripStartPivot extends BasicMsgPivot{*
	
	@DataField(pos = 1)
	private String msgType;

	@DataField(pos = 2)
	private BigDecimal test;

	@DataField(pos=3, pattern="ddMMyy")
	private Date team;



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Bindy-with-multiple-model-and-multiple-RouteBuilder-tp5746377.html
Sent from the Camel Development mailing list archive at Nabble.com.

Re: Camel Bindy with multiple model and multiple RouteBuilder

Posted by Richard Kettelerij <ri...@gmail.com>.
Please use users@camel.apache.org instead of dev@camel.apache.org for
support questions.


On Thu, Jan 23, 2014 at 7:55 AM, MohamedAli <tr...@gmail.com>wrote:

> *Main*
> List<String> msgList = new ArrayList<String>();
>                 msgList.add(place);
>                 msgList.add(placeTrip);
>                 msgList.add(place);
>                 msgList.add(tripStart);
>
>                 try {
>                         SpringCamelContext camelContext =
> SpringCamelContext
>
> .springCamelContext("Camel-Context.xml");
>                         System.out.println("Msg Pivot Test...");
>
>                         for (String msg : msgList) {
>                                 camelContext.start();
>
> camelContext.addRoutes(getRouteBuilder(msg, camelContext));
>                                 ProducerTemplate template = camelContext
>                                                 .createProducerTemplate();
>                                 //ConsumerTemplate consumerTemplate =
> camelContext.createConsumerTemplate();
>                                 //consumerTemplate.start();
>                                 template.sendBody(getConsumer(msg), msg);
>                                 //consumerTemplate.stop();
>                                 camelContext.stop();
>                         }
>                 } catch (Exception e) {
>                         e.printStackTrace();
>                         // TODO: handle exception
>                 }
>
> private static String getConsumer(String msg) {
>                 String builderName = null;
>                 if (msg != null) {
>                         if (msg.startsWith("$PLACE")) {
>                                 builderName = "direct:location";
>                         } else if (msg.startsWith("$READY")) {
>                                 builderName = "direct:trip";
>                         }
>                 }
>                 return builderName;
>         }
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Camel-Bindy-with-multiple-model-and-multiple-RouteBuilder-tp5746377p5746378.html
> Sent from the Camel Development mailing list archive at Nabble.com.
>

Re: Camel Bindy with multiple model and multiple RouteBuilder

Posted by MohamedAli <tr...@gmail.com>.
*Main*
List<String> msgList = new ArrayList<String>();
		msgList.add(place);
		msgList.add(placeTrip);
		msgList.add(place);
		msgList.add(tripStart);

		try {
			SpringCamelContext camelContext = SpringCamelContext
					.springCamelContext("Camel-Context.xml");
			System.out.println("Msg Pivot Test...");

			for (String msg : msgList) {
				camelContext.start();
				camelContext.addRoutes(getRouteBuilder(msg, camelContext));
				ProducerTemplate template = camelContext
						.createProducerTemplate();
				//ConsumerTemplate consumerTemplate =
camelContext.createConsumerTemplate();
				//consumerTemplate.start();
				template.sendBody(getConsumer(msg), msg);
				//consumerTemplate.stop();
				camelContext.stop();
			}
		} catch (Exception e) {
			e.printStackTrace();
			// TODO: handle exception
		}

private static String getConsumer(String msg) {
		String builderName = null;
		if (msg != null) {
			if (msg.startsWith("$PLACE")) {
				builderName = "direct:location";
			} else if (msg.startsWith("$READY")) {
				builderName = "direct:trip";
			}
		}
		return builderName;
	}



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Bindy-with-multiple-model-and-multiple-RouteBuilder-tp5746377p5746378.html
Sent from the Camel Development mailing list archive at Nabble.com.