2

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>
Community
  • 1
  • 1
Andriy Kryvtsun
  • 3,220
  • 3
  • 27
  • 41

1 Answers1

3

I remember as promised a contribution :-).

Re. <int-jpa:outbound-channel-adapter>:

  1. Any such an XML component is a Consumer Endpoint for the particular MessageHandler.

  2. 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...

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Thanks, Artem! Can you also help where is the place for injection `transactionManager` and input channel name? – Andriy Kryvtsun Mar 24 '16 at 22:04
  • The `JpaOutboundGatewayFactoryBean` has `txAdviceChain` option, where you should inject `TransactionInterceptor`. See `PollerSpec.transactional()` for a clue how to configure that. The `inputChannel` comes from the `IntegrationFlow` definition. The `.handle()` takes care about `ConsumerEndpointFactoryBean` for that `jpaMessageHandler`. Yeah.. I see it's enough complex. We have to implement JPA for DSL, if it is so popular. I was going to add `Splitters`, `Filters` etc. But looks like Spring is still so difficult for community, so we need to provide more and more high-level fluent API :-). – Artem Bilan Mar 24 '16 at 22:13
  • 1. Java DSL takes more code than the same XML config. 2. input threshold into Java DSL is higher but intention of DSLs is simplification. – Andriy Kryvtsun Mar 24 '16 at 22:31
  • OK. We will take that into account anyway. Any feedback is appreciate. Right now I only can say: that is a matter of opinion. My IDE allows me to code Java enough fast and with the method-chain support from the Framework it is really enough fluent. You should bear in mind that from the beginning Spring Integration was aimed for the XML world and there are really still some gaps for Java & Annotation configuration. – Artem Bilan Mar 24 '16 at 22:44