I want to integration test a custom camel component and therefor need an embedded/in memory messanging I can easily use to test from/to endpoints.
I am hoping that I can achieve this via spring-boot-amqp-starter.
I used this example for a start, which has the dependencies:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-broker</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
</dependency>
and the config:
spring:
activemq:
broker-url: vm://embedded?broker.persistent=false,useShutdownHook=false
// ...
This is working, when I use regular Listener annotations in spring, I have a sender using the template and a consumer logging the messages.
Now I go one step further and use camel, but it does not recognize the vm:embedded broker but tries to connect to tcp://localhost, which is not running.
return new RouteBuilder() {
#Override
public void configure() throws Exception {
from("activemq:foo").to("log:sample");
from("timer:bar").setBody(constant("Hello from Camel")).to("activemq:foo");
}
};
How can I configure activemq-camel to use the embedded broker?
Update:
I use dependency management imports for spring-boot-dependencies (1.5.9)
and camel-spring-boot-dependencies (2.20.1).
This has been fixed in newer versions of activemq-camel when you use that with Spring Boot. Now the activemq-camel component will honor the spring boot configuration of the spring.activemq.* settings.
Related
I was working on the Spring Boot Update to 3.0.1 and with it the Upgrade of Spring Integration 6.0.0 and Spring Cloud Stream 4.0.0. After upgrading however my previously working Spring Integration Flow is failing with underlying ClassCastException:
class org.springframework.messaging.handler.HandlerMethod$HandlerMethodParameter cannot be cast to class java.lang.reflect.Type (org.springframework.messaging.handler.HandlerMethod$HandlerMethodParameter is in unnamed module of loader 'app'; java.lang.reflect.Type is in module java.base of loader 'bootstrap')
Update: The exception originates from JsonMessageConverter inside of Spring Cloud Function Context, when trying to cast an object conversionHint (in my case of type HandlerMethodParameter) to Type.
Cannot cast 'org.springframework.messaging.handler.HandlerMethod$HandlerMethodParameter' to 'java.lang.reflect.Type'
Any hints or suggestions as to what might be the problem are highly appreciated.
Following is a highly shortened version of the affected integration flow and corresponding code snippets and a more detailed explanation:
#Bean
IntegrationFlow extract(SessionFactory<SftpClient.DirEntry> sftpSessionFactory,
XmlFileTransformer xmlFileTransformer){
return IntegrationFlow
.from(Sftp.inboundAdapter(sftpSessionFactory)
.preserveTimestamp(true)
.remoteDirectory("foo")
.regexFilter(".*\\.txt$")
.localDirectory(new File("sftp-inbound")), e -> e.id("sftpInboundAdapter")
.autoStartup(true)
.poller(Pollers.fixedDelay(5000))
)
.log(LoggingHandler.Level.DEBUG, "ExtractFlow", m -> "Successfully reached")
.wireTap(MONITORING_FLOW)
.log(LoggingHandler.Level.DEBUG, "ExtractFlow", m -> "Successfully done wire tap")
.transform(xmlFileTransformer)
.log(LoggingHandler.Level.DEBUG, "ExtractFlow", m -> "Successfully done transformation")
.handle(m -> xmlProcessor.process((XmlFile) m.getPayload())
.get();
}
#RequiredArgsConstructor
#Component
public class XmlFileTransformer implements GenericTransformer<Message<File>, XmlFile> {
#Override
public XmlFile transform(Message<File> message) {
return new XmlFile(message.getPayload().toPath(), message.getHeaders().get("x-origin", String.class));
}
}
The Integration Flow from the wiretap again transforms by implementing GenericTransfomer (similary written as XmlFileTransformer and then uses Amqp.outboundAdapter to send messages.
The method xmlProcessor.process takes XmlFile as argument. However it never reaches the actual method because it breaks when trying to go through the wire tap, and in case I comment the wire tap it breaks when trying to transform with xmlFileTransformer. So after log message "Successfully reached" the exception happens.
I'm using following relevant dependencies (other used dependencies not listed for better overview):
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>2022.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.1</version>
<relativePath/>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-rabbit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-sftp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-xml</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-amqp</artifactId>
</dependency>
</dependencies>
I was checking and rechecking my dependencies to ensure that I don't have any old dependencies that might clash with the update. However those should be fine as I'm using mostly the versions from spring-boot-starter-parent.
According to the migration guide of Spring Integration 6.0.0 there shouldn't be any major breaks that I forgot to handle.
I was trying to find any information about similar cases however it seems not too many have either tried to upgrade to Spring Boot 3 yet or just didn't have the same issues as me.
Could this be a bug in Spring Integration or do I need to refactor code so it's still running in Spring Integration 6.0? Or did I overlook issues with my dependencies?
I am working on integrating the camel springboot component with hawtio. I can't see the camel tab in the hawtio UI. I am using below dependencies of springboot camel and hawtio
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>io.hawt</groupId>
<artifactId>hawtio-springboot</artifactId>
<version>2.10.1</version>
</dependency>
This the sample route i configured, route is working as expected
#Component
public class SampleRoute extends org.apache.camel.builder.RouteBuilder{
#Override
public void configure() throws Exception {
from("kafka:test123?brokers=localhost:9092&allowManualCommit=true&autoCommitEnable=false&breakOnFirstError=true&maxPollRecords=1&synchronous=true")
.process(exchange -> {
exchange.getIn().setBody("test1234");
}).to("stream:out");
}
}
After reading many articles , i added below set of properties and it seems to have any effect.
management.endpoints.web.exposure.include=hawtio,jolokia
management.endpoints.jolokia.sensitive=false
endpoints.jolokia.sensitive = false
hawtio.authenticationEnabled=false
spring.jmx.enabled=true
camel.springboot.endpoint-runtime-statistics-enabled=true
management.endpoint.camelroutes.enabled=true
management.info.camel.enabled=true
management.endpoint.camelroutes.enabled=true
management.endpoint.camelroutes.read-only=true
camel.springboot.jmx-enabled=true
One of the solution worked for me is by downgrading to camel 2.X , but no luck with camel 3.X
I got it working, following the link as suggested. I had to remove the conflicting dependencies and adding below dependency worked.
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-management</artifactId>
<version>3.2.0</version>
</dependency>
I am writing service based on Spring webflux, which reads data from PostgreSQL using r2dbc. I need to use latest release of r2dbc, however I am getting NoSuchMethodError exception in using TransactionSynchronizationManager spring-tx 5.2.0.RELEASE library.
I basically need to know what is correct spring-tx library version to be compatible with version of spring-data-r2dbc which works correctly with latest r2dbc-postgresql and r2dbc-spi libraries.
Here are my Maven dependencies.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-r2dbc</artifactId>
<version>1.0.0.M2</version>
</dependency>
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-postgresql</artifactId>
<version>0.8.0.RC2</version>
</dependency>
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-spi</artifactId>
<version>0.8.0.M8</version>
</dependency>
I am using interface extending ReactiveCrudRepository interface to retrieve table data per below.
#Query("...")
Flux<QuoteHistory> findAllBySecIdAndDateTimeBetweenAndUpdateTypeIn(LocalDate date, Long secId);
I was able to get this code to work with earlier versions of r2dbc-postgresql and r2dbc-spi but now I am getting following exception.
java.lang.NoSuchMethodError: org.springframework.transaction.reactive.TransactionSynchronizationManager.currentTransaction()Lreactor/core/publisher/Mono;
at org.springframework.data.r2dbc.connectionfactory.ConnectionFactoryUtils.doGetConnection(ConnectionFactoryUtils.java:88) ~[spring-data-r2dbc-1.0.0.M2.jar:1.0.0.M2]
at org.springframework.data.r2dbc.connectionfactory.ConnectionFactoryUtils.getConnection(ConnectionFactoryUtils.java:70) ~[spring-data-r2dbc-1.0.0.M2.jar:1.0.0.M2]
at org.springframework.data.r2dbc.core.DefaultDatabaseClient.getConnection(DefaultDatabaseClient.java:189) ~[spring-data-r2dbc-1.0.0.M2.jar:1.0.0.M2]
These are r2dbc dependencies which code works with.
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-r2dbc</artifactId>
<version>1.0.0.M1</version>
</dependency>
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-postgresql</artifactId>
<version>1.0.0.M7</version>
</dependency>
Please use the following dependency combination:
R2DBC Postgres: 0.8.0.RC2
R2DBC SPI: 0.8.0.RC2
Spring Data R2DBC: 1.0.0.RC1
Spring Framework: 5.2.0.RELEASE
Alternatively, go to https://start.spring.io to get a dependency-managed project with versions that work together.
I am writing a spring boot app that accesses stuff from an s3 bucket, but I get a NoClassDefFoundError when I use the starter spring-cloud-starter-aws dependency from the spring initializer.
Am I missing some other dependency here?
Below are my dependencies.
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-aws</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-cassandra</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-integration</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
I also defined the dependencyManagement block for spring-cloud-dependencies and use Edgware.SR1 as my spring-cloud-version.
My app fails with the following error when starting up.
2018-01-24 12:20:25.642 INFO 1980 --- [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-01-24 12:20:25.666 ERROR 1980 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.art.productattribution.consumerintegration.ConsumerIntegrationApplication]; nested exception is java.lang.NoClassDefFoundError: com/amazonaws/AmazonClientException
at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:616) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
Not sure what am I missing here? Please let me know if you need any more details with this. The version of spring boot I am using is 1.5.9.RELEASE
The correct dependency is the spring-cloud-aws-context. Add the following in your pom file (version 1.2.2 as of Nov 22, 2017):
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-aws-context -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-aws-context</artifactId>
<version>1.2.2.RELEASE</version>
</dependency>
Below are the Spring Cloud AWS modules:
Spring Cloud AWS Core is the core module of Spring Cloud AWS providing basic services for security and configuration setup. Developers will not use this module directly but rather through other modules. The core module provides support for cloud based environment configurations providing direct access to the instance based EC2 metadata and the overall application stack specific CloudFormation metadata.
Spring Cloud AWS Context delivers access to the Simple Storage Service via the Spring resource loader abstraction. Moreover developers can send e-mails using the Simple E-Mail Service and the Spring mail abstraction. Further the developers can introduce declarative caching using the Spring caching support and the ElastiCache caching service.
Spring Cloud AWS JDBC provides automatic datasource lookup and configuration for the Relational Database Service which can be used with JDBC or any other support data access technology by Spring.
Spring Cloud AWS Messaging enables developers to receive and send messages with the Simple Queueing Service for point-to-point communication. Publish-subscribe messaging is supported with the integration of the Simple Notification Service.
Ref: http://cloud.spring.io/spring-cloud-aws/spring-cloud-aws.html#_using_amazon_web_services
It seems com.amazonaws.AmazonClientException is not found in the classpath. I think you can add the following dependency in your POM.xml file to solve this issue.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-aws-core</artifactId>
<version>1.2.2.RELEASE</version>
</dependency>
You need to include dependency mentioned by #alltej. Also you need to add below property in application.properties file if you are running on local.
cloud.aws.stack.auto=false
I have a Spring Boot project with Vaadin, I would like to integrate the Vaadin4Spring EventBus framework:
https://github.com/peholmst/vaadin4spring/tree/master/spring-vaadin-eventbus
The author says:
Please note, that the Event Bus API changed in version 0.0.5
However, if I add the Maven dependency inside my pom.xml:
...
<dependency>
<groupId>org.vaadin.spring</groupId>
<artifactId>spring-vaadin-eventbus</artifactId>
<version>LATEST</version>
</dependency>
...
Maven downloads the 0.0.4.RELEASE version. I have tried to explicitly set the following versions:
...
<dependency>
<groupId>org.vaadin.spring</groupId>
<artifactId>spring-vaadin-eventbus</artifactId>
<version>0.0.5</version>
</dependency>
...
...
<dependency>
<groupId>org.vaadin.spring</groupId>
<artifactId>spring-vaadin-eventbus</artifactId>
<version>0.0.5.RELEASE</version>
</dependency>
...
...
<dependency>
<groupId>org.vaadin.spring</groupId>
<artifactId>spring-vaadin-eventbus</artifactId>
<version>0.0.5-SNAPSHOT</version>
</dependency>
...
I also tried to set the entire Spring4Vaadin addon as a dependency:
<dependency>
<groupId>org.vaadin.spring</groupId>
<artifactId>spring-boot-vaadin</artifactId>
<version>LATEST</version>
</dependency>
...
<dependency>
<groupId>org.vaadin.spring</groupId>
<artifactId>spring-boot-vaadin</artifactId>
<version>0.0.5</version>
</dependency>
...
<dependency>
<groupId>org.vaadin.spring</groupId>
<artifactId>spring-boot-vaadin</artifactId>
<version>0.0.5-SNAPSHOT</version>
</dependency>
...
<dependency>
<groupId>org.vaadin.spring</groupId>
<artifactId>spring-boot-vaadin</artifactId>
<version>0.0.5.RELEASE</version>
</dependency>
But neither of them worked.
Basically, I cannot do this:
#Autowired
EventBus.ApplicationEventBUs appEventBus;
#Autowired
EventBus.UIEventBus UIEventBus;
...
Because, as said in the README.md on GitHub:
Please note, that the Event Bus API changed in version 0.0.5. From now
on, you have to declare which event bus to inject by using a specific
interface (previously, everything was EventBus and you used an
annotation to specify which bus to get). The reasons for this change
were
So in the version 0.0.4.RELEASE (which Maven sees as LATEST), the inner interfaces ApplicationEventBus and UIEventBus are not defined.
So, how can I use the true latest version of the addon?
Putting the answer I put in the vaadin forums, over here as well:
Vaadin addons has a nice Event Bus implementation. Check https://github.com/peholmst/vaadin4spring/tree/master/samples/eventbus-sample
I have done this using a spring enabled (NOT spring boot) Vaadin application, but it might work without Spring as well I guess, Short steps:
1. Add the following dependency
<dependency>
<groupId>org.vaadin.spring.addons</groupId>
<artifactId>vaadin-spring-addon-eventbus</artifactId>
<version>0.0.7.RELEASE</version>
</dependency>
Import EventBusConfiguration.class into your Spring configuration (may not be required if Spring Boot is used with #EnableAutoConfiguration)
Wire in appropriate event bus (check doumentations for different types available), here I am using one that works per UI instance:
#Autowired
private EventBus.UIEventBus uiEventBus;
Publish event as required, eg:
uiEventBus.publish(this, new RefreshMainViewEvent(this, "Usage details updated"));
Subscribe to event in the other component class
#PostConstruct
public void afterPropertiesSet() {
uiEventBus.subscribe(this, false);
}
Add the action to be done on event (in the same class here) :
#EventBusListenerMethod
public void closeSymmUsageWindow(RefreshMainViewEvent event) {
logger.debug("Received {}", event);
//blah
}