JPA outbound channel adapter config in Spring Integration Java DSL - java

I see there is still no JPA high-level support in Spring Integration Java DSL
Example Spring integration DSL for JPA Inbound Channel adapter
But how it is possible to configure JPA outbound channel adapter on low level?
E.g. to create Java DSL config like this in XML
<int-jpa:outbound-channel-adapter id="moduleMessagePersister" channel="inputPersisterChannel" persist-mode="MERGE" entity-manager-factory="entityManagerFactory">
<int-jpa:transactional transaction-manager="transactionManager"/>
</int-jpa:outbound-channel-adapter>

I remember as promised a contribution :-).
Re. <int-jpa:outbound-channel-adapter>:
Any such an XML component is a Consumer Endpoint for the particular MessageHandler.
See the latest changes in the Core project to help users to determine what to use for the Java & Annotation configuration. And therefore for Java DSL as well: https://jira.spring.io/browse/INT-3964
So, for this particular element we have:
<xsd:documentation>
Configures a Consumer Endpoint for the
'org.springframework.integration.jpa.outbound.JpaOutboundGatewayFactoryBean' (one-way)
updating a database using the Java Persistence API (JPA).
</xsd:documentation>
Therefore we have to configure something like
#Bean
public FactoryBean<MessageHandler> jpaMessageHandler() {
JpaOutboundGatewayFactoryBean factoryBean = new JpaOutboundGatewayFactoryBean();
...
factoryBean.setProducesReply(false);
return factoryBean;
}
And use it from the DSL:
#Bean
public IntegrationFlow jpaFlow(MessageHandler jpaMessageHandler) {
...
.handle(jpaMessageHandler)
.get();
}
Let me know what should be documented else!
And yes: we definitely should utilize JPA adapters in the next 1.2 Java DSL version...

Related

How To Override Default SQS Configurations For Spring Cloud AWS Messaging

Specifically looking to override the default AmazonSQSAsync client in order to ensure that the client is compatible with FIFO queues as mentioned in the version 2.4.2 documentation here . Defining a bean in my application in a #Configuration class similar to the documentation (as shown below) still results in the warning AmazonSQSBufferedAsyncClient that Spring Cloud AWS uses by default to communicate with SQS is not compatible with FIFO queues. Consider registering non-buffered AmazonSQSAsyncClient bean. Although, requests do seem to work I have not yet been able to determine if the correct AmazonSQSAsync client is being used. I'm looking for either a way to adjust my configuration that removes this warning (because my
AmazonSQSAsync bean is being used) or way to confirm that the message is actually a red herring. The dependency I'm using is spring-cloud-aws-messaging version 2.4.2
#Configuration
public class SQSConfig {
#Bean
public AmazonSQSAsync amazonSQS(#Value("${aws.region}") String awsRegion) {
return AmazonSQSAsyncClientBuilder.standard()
.withCredentials(DefaultAWSCredentialsProviderChain.getInstance())
.withRegion(awsRegion)
.build();
}
}
Looks like it was an error with configuration. I had mistakenly left the xml configuration <aws-messaging:annotation-driven-queue-listener /> active which was the source of the erroneous SQS client. Removing that xml configuration and including an override of the amazonSQS bean (bean name must match exactly) with an instance of AmazonSQSAsync solved the issue.

Enable schemaCreationSupport in spring-boot-starter-data-solr

I use spring-boot-starter-data-solr and would like to make use of the schmea cration support of Spring Data Solr, as stated in the documentation:
Automatic schema population will inspect your domain types whenever the applications context is refreshed and populate new fields to your index based on the properties configuration. This requires solr to run in Schemaless Mode.
However, I am not able to achieve this. As far as I can see, the Spring Boot starter does not enable the schemaCreationSupport flag on the #EnableSolrRepositories annotation. So what I tried is the following:
#SpringBootApplication
#EnableSolrRepositories(schemaCreationSupport = true)
public class MyApplication {
#Bean
public SolrOperations solrTemplate(SolrClient solr) {
return new SolrTemplate(solr);
}
}
But looking in Wireshark I cannot see any calls to the Solr Schema API when saving new entities through the repository.
Is this intended to work, or what am I missing? I am using Solr 6.2.0 with Spring Boot 1.4.1.
I've run into the same problem. After some debugging, I've found the root cause why the schema creation (or update) is not happening at all:
By using the #EnableSolrRepositories annotation, an Spring extension will add a factory-bean to the context that creates the SolrTemplate that is used in the repositories. This template initialises a SolrPersistentEntitySchemaCreator, which should do the creation/update.
public void afterPropertiesSet() {
if (this.mappingContext == null) {
this.mappingContext = new SimpleSolrMappingContext(
new SolrPersistentEntitySchemaCreator(this.solrClientFactory)
.enable(this.schemaCreationFeatures));
}
// ...
}
Problem is that the flag schemaCreationFeatures (which enables the creator) is set after the factory calls the afterPropertiesSet(), so it's impossible for the creator to do it's work.
I'll create an issue in the spring-data-solr issue tracker. Don't see any workaround right now, other either having a custom fork/build of spring-data or extend a bunch of spring-classes and trying to get the flag set before by using (but doubt of this can be done).

convert spring integration beans to java config

I am using spring integration for ftp integration. Following is my config
<int:channel id="ftpChannel"/>
<int-ftp:outbound-channel-adapter id="ftpOutbound"
channel="ftpChannel"
remote-directory="/"
session-factory="ftpClientFactory">
<int-ftp:request-handler-advice-chain>
<int:retry-advice />
</int-ftp:request-handler-advice-chain>
</int-ftp:outbound-channel-adapter>
How do I convert this to java based spring configuration?
From one side, please, pay attention that we have already Spring Integration Java DSL project and you can find there the FTP test-cases to figure out how to configure the FTP adapter from Java and DSL perspective.
From other side you should take a look to the Spring Integration Reference Manual, Annotation Configuration chapter to figure out what is #ServiceActivator, #Transformer and others. Your particular case may look like:
#Bean
#ServiceActivator(inputChannel = "ftpChannel", adviceChain = "retryAdvice")
public MessageHandler ftpHandler() {
FileTransferringMessageHandler handler = new FileTransferringMessageHandler(this.ftpClientFactory);
handler.setRemoteDirectoryExpression(new LiteralExpression("/"))
return handler;
}
and so on.
The retryAdvice in my sample is bean name for the RequestHandlerRetryAdvice.

What is the java config equivalent to tcp-outbound-gateway?

I have the following spring-integration XML config
<ip:tcp-outbound-gateway id="outboundClient"
request-channel="requestChannel"
reply-channel="string2ObjectChannel"
connection-factory="clientConnectionFactory"
request-timeout="10000"
reply-timeout="10000"/>
How can I write the Java config equivalent of the above?
I thought the equivalent would be
#Bean
public TcpOutboundGateway outboundClient() {
TcpOutboundGateway tcpOutboundGateway = new TcpOutboundGateway();
tcpOutboundGateway.setConnectionFactory(clientConnectionFactory());
tcpOutboundGateway.setRequiresReply(true);
tcpOutboundGateway.setReplyChannel(string2ObjectChannel());
tcpOutboundGateway.setRequestTimeout(10000);
tcpOutboundGateway.setSendTimeout(10000);
return tcpOutboundGateway;
}
But I couldn't find a way to set the request channel.
Any help would be appreciated.
Thank you
Your config looks good, but you should know in addition that any Spring Integration Consumer component consists of two main objects: MessageHandler (TcpOutboundGateway in your case) and EventDrivenConsumer for subscriable input-channel or PollingConsumer if input-channel is Pollable.
So, since you already have the first, handling, part you need another consuming. For this purpose Spring Integration suggests to mark your #Bean with endpoint annotations:
#Bean
#ServiceActivator(inputChannel = "requestChannel")
public TcpOutboundGateway outboundClient() {
See more in the Spring Integration Reference Manual.
However to allow such a annotation process (or any other Spring Integration infrastructure) you have to mark your #Configuration with #EnableIntegration.
Also consider to use Spring Integration Java DSL to have more gain from JavaConfig.

JMS outbound channel adapter java-based configuration

Is there any way to configure JMS outbound channel adapter
<int-jms:outbound-channel-adapter id="jmsOut" destination="outQueue" channel="exampleChannel"/>
by the similar "easy" way, but using only java-based (annotations) configuration?
If no, so what is the simplest way to achieve this point?
Eugene, I've already pointed you out to the Spring Integration Java DSL. It is exactly the best way to simplify Spring Integration from Java-based config.
Since it isn't the first your similar question, please, pay attention to that project, which has a simple fusion with Core SI:
#Bean
public IntegrationFlow jmsOutboundFlow() {
return IntegrationFlows.from("exampleChannel")
.handleWithAdapter(h ->
h.jms(this.jmsConnectionFactory).destination("outQueue"))
.get();
}
Otherwise it may look like this for the raw Java & Annotation configuration:
#Bean
#serviceActivator(inputChannel = "exampleChannel")
public MessageHandler jsmOutboundAdapter() {
JmsTemplate template = new DynamicJmsTemplate();
template.setConnectionFactory(this.jmsConnectionFactory);
JmsSendingMessageHandler handler = new JmsSendingMessageHandler(template);
handler.setDestinationName("outQueue");
return handler;
}

Categories

Resources