import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.infinispan.InfinispanConstants;
import org.apache.camel.component.jackson.JacksonDataFormat;
import org.apache.camel.model.dataformat.JsonLibrary;
import uk.co.sammy.model.Collection;
public class InfinispanRoute extends RouteBuilder {
private JacksonDataFormat json = new JacksonDataFormat(Collection.class);
#Override
public void configure() throws Exception {
from("file:src/data?noop=true&include=.*.json")
.choice()
.when()
.jsonpath("$..CustInfo[?(#.firstName == 'Sammy')]").unmarshal(json)
.log("Got customer data for ${body.custInfo.firstName}")
.setHeader(InfinispanConstants.OPERATION, constant(InfinispanConstants.PUT_IF_ABSENT))
.setHeader(InfinispanConstants.KEY, simple("${body.custInfo.firstName}"))
.to("infinispan://localhost")
.marshal().json(JsonLibrary.Jackson)
.to("activemq:queue:incomingApplication", "activemq:queue:customerDetails");
from("activemq:queue:incomingApplication")
.setHeader(InfinispanConstants.OPERATION, constant(InfinispanConstants.GET))
.setHeader(InfinispanConstants.KEY, constant("${body.custInfo.firstName}"))
.to("infinispan://foo?cacheName=localCache")
.setBody(simple("${header.CamelInfinispanOperationResult}"))
.to("activemq:output");
}
}
My pom.xml looks like the below
<properties>
<activemq.version>5.14.1</activemq.version>
<camel.version>2.18.0</camel.version>
<infinispan.version>8.3.0.Final-redhat-1</infinispan.version>
<camel-jbossdatagrid.version>6.6.1.Final-redhat-1</camel-jbossdatagrid.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jackson</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jsonpath</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-embedded</artifactId>
<version>${infinispan.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jbossdatagrid</artifactId>
<version>${camel-jbossdatagrid.version}</version>
</dependency>
<!--ActiveMQ -->
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-camel</artifactId>
<version>${activemq.version}</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-pool</artifactId>
<version>${activemq.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.10</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-all</artifactId>
<version>5.1</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>fuse-release</id>
<name>jboss Release Repository</name>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>http://repo.fusesource.com/nexus/content/groups/public/</url>
</repository>
</repositories>
</project>
I have tried for three days to get this simple sample code to work with Infinispan using the REdhat getting started guide and downloaded the quickstart zip to run that but still won't work! I keep getting the error "cannot connect to foo:11222" or "pool not open" by Spring JMS then a warning about mixing Uber and Jars version. I started off using ehcache which was a pain to implement because of limited simple examples that show how to store, retrieve and clear a cache from rest calls etc. Now, I need this to work so I can easily migrate it to Openshift but, still won't work! Every time I restart the project, I get different errors. Please any help to step by step setup Infinispan to work using my above code will be SERIOUSLY appreciated. Thanks guys!
P.S: I've read through the Redhat data grid getting started page and followed their instructions before doing this as my last resort!!!
Using the "infinispan://localhost" uri format will try to connect to an Infinispan server. To use an embedded cache, you should use something like "infinispan://?cacheName=localCache"
I see a few errors in the example you have provided:
1st route:
You should set the value you want to put in the cache with InfinispanConstants.VALUE
2nd route:
You should use the same cache uses by the first route (i.e. same cache name)
You should use simple to set InfinispanConstants.KEY
Related
Context:
I have to rewrite a parent library from Java EE to a more modern one in Spring Boot. For example, it has got some deprecated dependencies and CDI parts, Microprofiles that are not Spring compatible.
Problem:
I have hardly used OpenTelemetry and OpenTracing. I understand only the high-level concepts but I have never coded such things. I have trouble rewriting a part that involves OpenTracing. I know OpenTracing is deprecated and I should use OpenTelemetry. There is a dependency called 'Tracer Resolver'.
Its description from Github: Resolver API for OpenTracing Tracer implementations. NOTE: The Tracer Resolver mechanism is only intended to be used at application startup/initialization time. This responsibility should be handled by the application, possibly using some runtime-specific support (e.g. providing a Tracer #Bean in Spring Boot, or a CDI producer). Framework integrations used to instrument-specific technologies should not use this library, but should allow a Tracer to be injected instead, with fallback to the GlobalTracer.
In the code the only OpenTracing dependency:
<dependency>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-tracerresolver</artifactId>
<version>0.1.8</version>
</dependency>
And I found the usage in the code as:
#ApplicationScoped
public class OpenTraceResolver {
#Inject
private Instance<Tracer> tracerInstance;
...
or
#Provider
public class OpenTraceErrorResponseFilter implements ContainerResponseFilter {
#Inject
private Tracer configuredTracer;
...
How should I do the same with OpenTelemetry? Is there a way to use it in such a simple way?
Thank you for your help!
First of all Spring uses Spring Cloud Sleuth project for implementing distributed tracing and you need add it to your project before configure open telemetry. By default Spring Cloud Sleuth uses OpenZipkin Brave by default which is different from OpenTelemetry (Otel) implementation.
To configure you project to use OpenTelemetry you need to decide if you will go with auto-instrumentation which is easier (using agents on not) or with manual instrumentation, with gives you more flexibility.
With auto-instrumentation you just need change your pom.xml and configure an exporter backend in your application.yaml and it will automatically generate and export the traces for you.
application.yaml
spring.sleuth.otel.exporter.otlp.endpoint=[URL TO YOUR OTEL BACKEND]
you can send the traces do zipkin, grafana tempo and etc..
pom.xml
<properties>
<spring-cloud.version>2021.0.0-M2</spring-cloud.version>
<spring-cloud-sleuth-otel.version>1.1.0-M3</spring-cloud-sleuth-otel.version>
<opentelemetry-exporter-otlp>1.7.0</opentelemetry-exporter-otlp>
<grpc-netty-shaded>1.41.0</grpc-netty-shaded>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- Spring Cloud Sleuth OTel requires a Spring Cloud Sleuth OTel BOM -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-otel-dependencies</artifactId>
<version>${spring-cloud-sleuth-otel.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<!-- Sleuth with Brave tracer implementation -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
<exclusions>
<!-- Exclude Brave (the default) -->
<exclusion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-brave</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Add OpenTelemetry tracer -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-otel-autoconfigure</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/io.opentelemetry/opentelemetry-exporter-otlp -->
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-otlp</artifactId>
<version>${opentelemetry-exporter-otlp}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.grpc/grpc-netty -->
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
<version>${grpc-netty-shaded}</version>
</dependency>
<repositories>
<repository>
<id>spring-snapshots</id>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<url>https://repo.spring.io/snapshot</url>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<url>https://repo.spring.io/milestone</url>
</pluginRepository>
</pluginRepositories>
More references
https://opentelemetry.io/docs/instrumentation/java/
https://github.com/spring-projects-experimental/spring-cloud-sleuth-otel
I am using confluent and according to the official document, I only have to configure below in pom.xml like this:
<repositories>
<repository>
<id>confluent</id>
<url>http://packages.confluent.io/maven/</url>
</repository>
<!-- further repository entries here -->
</repositories>
<dependencies>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.11</artifactId>
<!-- For CP 3.1.0 -->
<version>0.10.1.0-cp1</version>
</dependency>
</dependencies>
But seems kafka_2.11 with version 0.10.1.0-cp1 does not exits.
The website http://packages.confluent.io/maven/ cannot be reached too.
How can I get it?
I am using below maven dependancy its working fine for me :
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>connect-api</artifactId>
<version>0.10.2.0-cp1</version>
</dependency>
<repository>
<id>confluent</id>
<name>Confluent</name>
<url>http://packages.confluent.io/maven/</url>
</repository>
Hopefully this will help
I am currently getting into Spigot Pugin developement and need to access GameProfile, because I need it for a plugin (Stuff for changing Skins). I'm using Eclipse.
Now, I've watched a whole ton of tutorials in which GameProfile was used, and all these tutorials just went for
import com.mojang.authlib.GameProfile;
or
import net.minecraft.util.SOMETHINGLONG.GameProfile
without needing to explain anything why this line is possible.
Here is a guy that had the same problem like me with the second command but apparently could solve it with the first one, so im trying to get this one running. https://www.spigotmc.org/threads/how-to-import-net-minecraft-util.252371/.
If I try to include stuff like this, I see com.google.common, com.oracle and com.sun but com.mojang is nowhere to be seen. I found it has to do something with the .jar files you add to your project, but I don't know how to get com.mojang... into the importable files.
To build up on SPY_me's answer, here is my solution if you're using Gradle:
repositories {
// ...
maven {
name = 'minecraft-repo'
url = 'https://libraries.minecraft.net/'
// this lets gradle know where to look for authlib
}
}
dependencies {
// ...
compile 'com.mojang:authlib:1.5.21'
// this adds the library to the project and the jar when you compile your project
}
If you want to download this library directly, here is the jar:
https://libraries.minecraft.net/com/mojang/authlib/1.5.21/authlib-1.5.21.jar
<repositories>
<repository>
<id>minecraft-repo</id>
<url>https://libraries.minecraft.net/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.mojang</groupId>
<artifactId>authlib</artifactId>
<version>1.5.21</version>
<scope>provided</scope>
</dependency>
</dependencies>
Since you use Intellij i guess youre using Maven?
If so then paste this in your pom.yml:
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<!--Spigot API-->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!--Bukkit API-->
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!--CraftBukkit API-->
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
I want to write files to hdfs present on a remote server and came across few examples like this and this. I have Cdh4.2.1 on my remote server and when from my code I try to do import org.apache.hadoop.conf.Configuration;, I get the following error:
Cannot resolve Configuration
My pom.xml looks like:
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.4.1</version>
</dependency>
In this SO post, the pom.xml looks different and when I try to put those versions in my pom, the maven does not recognize it.
How can I resolve this issue?
Try using just the hadoop-client dependency and use cloudera specific version as you are using CDH like this:
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
<version>2.0.0-cdh4.2.1</version>
</dependency>
Also make sure you have the following repositories to resolve the jar dependencies:
<repository>
<id>maven-hadoop</id>
<name>Hadoop Releases</name>
<url>https://repository.cloudera.com/content/repositories/releases/</url>
</repository>
<repository>
<id>cloudera-repos</id>
<name>Cloudera Repos</name>
<url>https://repository.cloudera.com/artifactory/cloudera-repos/</url>
</repository>
when trying to read GeoTiff data using geotiff-jai, I am not able to register GeoTIFFDescriptor:
#Test
public void canGetTiffDecoder() {
Iterator<ImageReader> reader = ImageIO.getImageReadersByFormatName("tiff");
assertNotNull(reader);
assertTrue(reader.hasNext());
GeoTIFFDescriptor.register(); // this line is causing errors
}
When this test is executed, I am getting: No descriptor by name "tiff" is registered under mode "rendered".
Exception in thread "main" java.lang.IllegalArgumentException: No descriptor by name "tiff" is registered under mode "rendered".
at javax.media.jai.OperationRegistry.registerFactory(OperationRegistry.java:1173)
at javax.media.jai.ThreadSafeOperationRegistry.registerFactory(ThreadSafeOperationRegistry.java:330)
at javax.media.jai.OperationRegistry.registerRIF(OperationRegistry.java:2176)
at org.libtiff.jai.operator.XTIFFDescriptor.register(XTIFFDescriptor.java:132)
at org.geotiff.image.jai.GeoTIFFDescriptor.register(GeoTIFFDescriptor.java:48)
at in.drifted.tiler.GeoTiffFile.main(GeoTiffFile.java:18)
My POM:
<repositories>
<repository>
<id>jai-repo</id>
<url>http://dev.mapfish.org/maven/repository/</url>
<layout>default</layout>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>javax.media</groupId>
<artifactId>jai_core</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>javax.media</groupId>
<artifactId>jai_codec</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>javax.media</groupId>
<artifactId>jai_imageio</artifactId>
<version>1.1</version>
</dependency>
<!-- installed manually -->
<!-- http://sourceforge.net/projects/geotiff-jai -->
<dependency>
<groupId>net.sf.geotiff-jai</groupId>
<artifactId>geotiff-jai</artifactId>
<version>2.0</version>
</dependency>
<!-- http://sourceforge.net/projects/xtiff-jai/ -->
<dependency>
<groupId>net.sf.xtiff-jai</groupId>
<artifactId>xtiff-jai</artifactId>
<version>0.3</version>
</dependency>
</dependencies>
JDK 1.8, Win7
Any idea, why TIFF cannot be registered correctly?
Thanks, Jan
I've tracked down the issue. There is 'xtiff' GlobalName/LocalName specified in the original XTIFFDescriptor.java, but I thought it is 'tiff' (expecting there are no modifications in the following source:
http://opensourcejavaphp.net/java/openjump/org/libtiff/jai/operator/XTIFFDescriptor.java.html
I got rid this issue by copying the modified class to my project which overrides that one in the xtiff-jai library.