Spring Integration: configure default errorChannel - spring-integration

when starting the spring boot integration project on which I’m working on, following Info log is shown:
No bean named 'errorChannel' has been explicitly defined. Therefore, a default PublishSubscribeChannel will be created.
Is there a way to configure the queue name for this default Bean using only yaml/json paramenters, without explicitly create the Bean?

No there is not; you explicity need to declare a MessageChannel bean named errorChannel to replace the default error channel and its configuration.

Related

Micrometer #Timed annotation write logs to file?

How to configure spring-boot Micrometer #Timed annotation to write logs into some log file instead of endpoint?
To write all metrics to logs you can use the LoggingMeterRegistry. There is no autoconfiguration for this in spring boot so if you are using spring boot you will need to configure the required beans manually.
Source code: https://github.com/micrometer-metrics/micrometer/blob/master/micrometer-core/src/main/java/io/micrometer/core/instrument/logging/LoggingMeterRegistry.java

how to threat errors on spring cloud dataflow?

When deploying my microservice on spring cloud dataflow I get the following log:
No bean named 'errorChannel' has been explicitly defined. Therefore, a default PublishSubscribeChannel will be created
how do I direct error flows?
My guess is to create an errorChannel bean (as the message says). But I did not find any docs about it nor sample usages.
For example, I have a sink that executes an Insert on a database and want to direct it elsewhere if insert fails.
The default errorChannel bean has a LoggingHandler subscribed to it.
If you define your own errorHandler channel, it won't get the default LoggingHandler.
The error channel is automatically wired in.
Each consumer (or #StreamListener) gets a dedicated error channel binding.group.errors which is bridged to the global errorChannel.
You can add a #ServiceActivator to consume ErrorMessages from either of these channels.
Error channels are not applied on the producer side; you have to catch the exception yourself.

No transaction behaviour needed in Spring Data

I am trying to figure it out how to configure a method not to run within a transaction using Spring. I have read that the Spring Data repositories by default activate the transactional behaviour in its methods. I dont want this transaction because I have many "save" calls to a repository and each of them is independent from the other. I think creating a transaction for each call to a repository method can slow down the code and the performance of the app. So :
Is this possible or every service or dao method has to run within a transaction?
If it has, why?
If this is possible, how to configure a method not to run within a transaction? Just removing the Spring transactional annotation?
Thanks
Spring service beans by default are not transactional. You can add the #Transactional at a class or a method level to force it to be transactional. Here are a few links explaining in detail on how transactional in Spring works.
What is the difference between defining #Transactional on class vs method .
Spring - #Transactional - What happens in background? .
https://docs.spring.io/spring/docs/4.2.x/spring-framework-reference/html/transaction.html#tx-decl-explained .
It is also discussed in the below thread .
Is Spring #Service transactional?

How to add properties via Spring TestExecutionListener

I created a TestExecutionListener to run a docker container for integration testing. I would like to be able to inject properties (eg container port) that can be used by #ConfigurationProperties annotated beans.
I thought I might be able to call TestPropertySourceUtils.addInlinedPropertiesToEnvironment(...) but when I try to get an application context object the context ends up fully loading before I can even attempt to inject any properties.
Is there any way to do this from a TestExecutionListener?
My workaround is to set the properties via System.setProperty(...) but that obviously does not permit any concurrency.
I'm running Spring Boot 2.1.1.RELEASE.

Create programatically message-driven-channel-adapter to process the messages on queue

I would like process the message programmatically using message-driven-channel-adapter. Here is scenario which I have to implement:
My application during the startup read the configuration from a service. The configuration provides information about the queues which will contain the messages. Hence I would like to create a message-driven-channel-adapter for each queue to listen to messages asynchronously.
Any example which initializes all the spring integration context programatically instead of using XML will be useful.
If you are going to do everything programmatically, I'd suggest you bypass Spring Integration magic and just use DefaultMessageListenerContainer directly.
Afterwards you can send messages to an existing MessageChannel directly from the MessageListener implementation or using Messaging Gateway.
Please, be careful with programmatic configuration with that do not miss important attributes like ApplicationContext or invocation for afterPropertiesSet().

Resources