Hey solomon, perhaps the following example helps?

    public class ExampleIgniteCacheTest extends CamelTestSupport {

        @EndpointInject(uri = "mock:result")
        protected MockEndpoint resultEndpoint;

        @Test
        public void testCache() throws Exception {

            String expectedBody = "abc";

            resultEndpoint.expectedBodiesReceived(expectedBody);

            template.sendBody("direct:doPut", "{\"id\":123,
\"data\":\"abc\"}");

            template.sendBodyAndHeader("direct:doGet", "",
IgniteConstants.IGNITE_CACHE_KEY, 123);

            resultEndpoint.assertIsSatisfied();
        }

        @Override
        protected RouteBuilder createRouteBuilder() {

            context.addComponent("ignite-cache",
IgniteCacheComponent.fromConfiguration(new IgniteConfiguration()));

            return new RouteBuilder() {
                @Override
                public void configure() {
                    from("direct:doPut")
                            .setHeader(IgniteConstants.IGNITE_CACHE_KEY,
new JsonPathExpression("$.id"))
                            .setBody(new JsonPathExpression("$.data"))
                            .log("putting: ${header.CamelIgniteCacheKey} =
${body}")
                            .to("ignite-cache:abc?operation=PUT");

                    from("direct:doGet")
                            .to("ignite-cache:abc?operation=GET")
                            .log("getting: ${header.CamelIgniteCacheKey} =
${body}")
                            .to("mock:result");
                }
            };
        }

    }

Regards,
Gary

On 8 June 2017 at 18:04, Claus Ibsen <claus.ib...@gmail.com> wrote:

> You need to set a header with the key name
> CamelIgniteCacheKey
>
> See the IgniteConstants class for the headers
>
> On Thu, Jun 8, 2017 at 12:52 PM, solomon <austin.solomon...@gmail.com>
> wrote:
> > Hi,
> >
> > I'm trying to listen from an mqtt topic which produces a json object and
> > store that data into apache Ignite's Cache using Apache camel contex, but
> > the data is not inserting to cache.
> >
> > my JSON data looks like this : {"id": 1, "data":"test"}
> >
> > and this is sample code snippet :
> >
> >          from("mqtt:bar?subscribeTopicName=test&host=
> tcp://localhost:1883")
> >         .setHeader("id", new JsonPathExpression("$.id"))
> >         .setHeader("data", new JsonPathExpression("$.data"))
> >         .process(new Processor() {
> >                 public void process(Exchange exchange)throws Exception {
> >                          exchange.getIn().setBody(
> > exchange.getIn().getBody(String.class));
> >                          System.out.println("Processing JSON Meassage: "+
> > exchange.getIn().getBody(String.class));
> >                 }
> >         })
> >         .to("ignite-cache:cache:myCacheName?operation=PUT");
> >
> > Can anyone help me what I am missing.
> >
> > How to insert the Key-Value into Ignite's cache and query it later.
> >
> >
> >
> > --
> > View this message in context: http://camel.465427.n5.nabble.
> com/Apache-Ignite-Example-tp5800977p5802573.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
>

Reply via email to