You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by solomon <au...@gmail.com> on 2017/05/27 06:24:05 UTC
Apache-Ignite Example
Hi,
I'm trying to run a camel program which gets the data from camel-mqtt
component and insert the data into camel-ignite-cache, however the data is
not inserting into Ignite's cache. There is no any errors while running
this.
I searched for camel-ignite example online but didn't get any.
My code snippet is like this
Ignite ignite = Ignition.start("examples/config/example-ignite.xml");
CacheConfiguration<Integer, String> cfg = new CacheConfiguration<>();
cfg.setCacheMode(CacheMode.PARTITIONED);
IgniteCache<Integer, String> cache =
ignite.getOrCreateCache("myCacheName");
IgniteDataStreamer<String, String> pipe =
ignite.dataStreamer("myCacheName");
CamelStreamer<String, String> streamer = new CamelStreamer<>();
streamer.setIgnite(ignite);
streamer.setStreamer(pipe);
CamelContext context = new DefaultCamelContext();
try {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("mqtt:bar?subscribeTopicName=test&host=tcp://localhost:1883")
.to("ignite-cache:myCacheName?operation=PUT", "1234",
IgniteConstants.IGNITE_CACHE_KEY, "abcd");
}
});
} catch (Exception e) {
e.printStackTrace();
}
streamer.setEndpointUri("ignite-cache:myCacheName?operation=PUT");
Can any one guide me on how to ingest data into Ignite's cache.
Thanks
--
View this message in context: http://camel.465427.n5.nabble.com/Apache-Ignite-Example-tp5800977.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Apache-Ignite Example
Posted by Claus Ibsen <cl...@gmail.com>.
I dont know what data type mqtt gives you, you can turn on tracer to
see that etc.
But you can also try to convert the data to a String.class before via
.convertBodyTo(String.class) assuming Ignite can store plain strings
and get them again via query.
On Fri, Jun 9, 2017 at 3:34 PM, solomon <au...@gmail.com> wrote:
> Hi Claus & Gary,
>
> I have set the header as .setHeader(IgniteConstants.IGNITE_CACHE_KEY, new
> JsonPathExpression("$.id"))
> now the data is getting inserted, when I checked the node entry in Ignite
> visor console count increases when message comes from the mqtt channel.
> However while querying the cache I'm getting the empty result.
>
> Do I need to map the object here or something I am missing ?
>
> Regards,
> Solomon
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Apache-Ignite-Example-tp5800977p5802804.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
Re: Apache-Ignite Example
Posted by solomon <au...@gmail.com>.
Hi Claus & Gary,
I have set the header as .setHeader(IgniteConstants.IGNITE_CACHE_KEY, new
JsonPathExpression("$.id"))
now the data is getting inserted, when I checked the node entry in Ignite
visor console count increases when message comes from the mqtt channel.
However while querying the cache I'm getting the empty result.
Do I need to map the object here or something I am missing ?
Regards,
Solomon
--
View this message in context: http://camel.465427.n5.nabble.com/Apache-Ignite-Example-tp5800977p5802804.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Apache-Ignite Example
Posted by Gary Hodgson <ga...@gmail.com>.
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 <cl...@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 <au...@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
>
Re: Apache-Ignite Example
Posted by Claus Ibsen <cl...@gmail.com>.
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 <au...@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
Re: Apache-Ignite Example
Posted by solomon <au...@gmail.com>.
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.
Re: Apache-Ignite Example
Posted by Claus Ibsen <cl...@gmail.com>.
See the camel-ignite documentation and the unit tests of itself to
find examples. You need to configure the camel ignite component with
some cache configuration.
On Sat, May 27, 2017 at 10:05 AM, solomon <au...@gmail.com> wrote:
> Hi Claus,
>
> I started the CamelContext, now getting the following exception
>
> Caused by: java.lang.IllegalStateException: No configuration resource or
> IgniteConfiguration was provided to the Ignite component.
> at
> org.apache.camel.component.ignite.IgniteComponent.doStart(IgniteComponent.java:170)
> at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
> at
> org.apache.camel.impl.DefaultCamelContext.startService(DefaultCamelContext.java:3219)
> at
> org.apache.camel.impl.DefaultCamelContext.getComponent(DefaultCamelContext.java:404)
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Apache-Ignite-Example-tp5800977p5801002.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
Re: Apache-Ignite Example
Posted by solomon <au...@gmail.com>.
Hi Claus,
I started the CamelContext, now getting the following exception
Caused by: java.lang.IllegalStateException: No configuration resource or
IgniteConfiguration was provided to the Ignite component.
at
org.apache.camel.component.ignite.IgniteComponent.doStart(IgniteComponent.java:170)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at
org.apache.camel.impl.DefaultCamelContext.startService(DefaultCamelContext.java:3219)
at
org.apache.camel.impl.DefaultCamelContext.getComponent(DefaultCamelContext.java:404)
--
View this message in context: http://camel.465427.n5.nabble.com/Apache-Ignite-Example-tp5800977p5801002.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Apache-Ignite Example
Posted by Claus Ibsen <cl...@gmail.com>.
You need to start CamelContext at least
On Sat, May 27, 2017 at 8:24 AM, solomon <au...@gmail.com> wrote:
> Hi,
>
> I'm trying to run a camel program which gets the data from camel-mqtt
> component and insert the data into camel-ignite-cache, however the data is
> not inserting into Ignite's cache. There is no any errors while running
> this.
>
> I searched for camel-ignite example online but didn't get any.
>
> My code snippet is like this
>
> Ignite ignite = Ignition.start("examples/config/example-ignite.xml");
>
> CacheConfiguration<Integer, String> cfg = new CacheConfiguration<>();
> cfg.setCacheMode(CacheMode.PARTITIONED);
>
> IgniteCache<Integer, String> cache =
> ignite.getOrCreateCache("myCacheName");
>
> IgniteDataStreamer<String, String> pipe =
> ignite.dataStreamer("myCacheName");
>
> CamelStreamer<String, String> streamer = new CamelStreamer<>();
> streamer.setIgnite(ignite);
> streamer.setStreamer(pipe);
>
> CamelContext context = new DefaultCamelContext();
> try {
> context.addRoutes(new RouteBuilder() {
> @Override
> public void configure() throws Exception {
>
> from("mqtt:bar?subscribeTopicName=test&host=tcp://localhost:1883")
> .to("ignite-cache:myCacheName?operation=PUT", "1234",
> IgniteConstants.IGNITE_CACHE_KEY, "abcd");
> }
> });
> } catch (Exception e) {
> e.printStackTrace();
> }
> streamer.setEndpointUri("ignite-cache:myCacheName?operation=PUT");
>
>
> Can any one guide me on how to ingest data into Ignite's cache.
>
> Thanks
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Apache-Ignite-Example-tp5800977.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