Spring Kafka error handling - v1.1.x - error-handling

How to deal with error handling in spring-kafka version 1.1.x?
As I see it was introduced in version 2.0...

In 1.x you can add an ErrorHandler implementation to the listener container (or container factory if you are using #KafkaListener annotations).
The 2.0 feature was added to make it easier to configure if you want a different error handler for each listener when using annotations.

Related

Error creating bean named `conversionServicePostProcessor` when using spring-boot-admin-server

I was trying to enable Spring boot admin server for my application. The default settings work perfectly fine but when I attempt to enable security, I am getting following error:
APPLICATION FAILED TO START
Description:
The bean 'conversionServicePostProcessor', defined in class path
resource
[org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class],
could not be registered. A bean with that name has already been
defined in class path resource
[org/springframework/security/config/annotation/web/reactive/WebFluxSecurityConfiguration.class]
and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting
spring.main.allow-bean-definition-overriding=true
Process finished with exit code 1
I am using the latest SNAPSHOT version of spring-boot-admin-starter-server (2.2.0-SNAPSHOT). Here is my security configuration:
#EnableAdminServer
#EnableWebFluxSecurity
#Configuration(proxyBeanMethods = false)
class AdminServerSecurityConfigurations(val adminServerProperties: AdminServerProperties) {
#Bean
fun adminServerSecurityWebFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain = http
// #formatter:off
.authorizeExchange()
.pathMatchers("${adminServerProperties.contextPath}/assets/**").permitAll()
.pathMatchers("${adminServerProperties.contextPath}/login").permitAll()
.anyExchange().authenticated().and()
.formLogin().loginPage("${adminServerProperties.contextPath}/login").and()
.logout().logoutUrl("${adminServerProperties.contextPath}/logout").and()
.httpBasic().and()
// #formatter:on
.csrf().disable()
.build()
#Bean
fun notifyLogger(instanceRepository: InstanceRepository) = LoggingNotifier(instanceRepository)
}
I found a pull request to update the documentation: https://github.com/spring-projects/spring-boot/issues/14069
For Reactive WebSockets,
{spring-reference}web-reactive.html#webflux-websocket[Spring WebFlux] offers rich support,
which is accessible through the spring-boot-starter-webflux module.
See the spring-boot-sample-websocket-reactive sample project to see how WebSockets may
be implemented using Spring WebFlux.
it turns out that using webflux and websocket leads to conflicts.
also in this pull request was denied in the resolution of the conflict
https://github.com/spring-projects/spring-boot/issues/14810
for reactive websocket see this sample https://www.baeldung.com/spring-5-reactive-websockets
I had the same issue and was able solve it by adding
spring.main.allow-bean-definition-overriding=true
to my application.properties.
Sounds like a workaround and it was also only necessary if I deployed it as WAR -- as a standalone application the exception never occured.
I also faced this error, after Reimport All Mavne Projects(Intellij IDE) it works fine for me. Here my detailed input on this issue here

Skip loading of a jar file in WebSphere 8.5.5

I am getting an exception as given below.
I want Response class to be loaded from jawax-ws-rs.api.jar.
but its getting loaded from the j2ee.jar and throwing the below error:-
java.lang.NoSuchMethodError: javax/ws/rs/core/Response.readEntity(Ljava/lang/Class;)Ljava/lang/Object
Is there any way we can skip loading of j2ee.jar at startup of WebSphere?
Your question is incorrect, probably what you really want is to replace JAX-RS engine provided with WAS with some third part. And you should never pack j2ee.jar with your application as all required classes are already loaded by the server.
Check the following posts and links:
JAX-RS Jersey 2.10 support in Websphere 8
Disabling the JAX-RS runtime environment

Mule DevKit Connectors, Connection Management and reconnect policies

Should a custom Mule connector written using the DevKit be compatible by default with reconnection policies. e.g., I wrote a connector using connection management following http://www.mulesoft.org/documentation/display/current/Implementing+Connection+Management
When I set up an error condition and my #Connect method throws a ConnectionException my flow stops and the connector doesn't try to reconnect despite having a global config element:
<configuration>
<reconnect-forever frequency="2000"/>
</configuration>
I know this config is working because it has the expected effect on a JDBC transport but not on my custom connector.
Am I missing something fundamental? Should custom connectors work at all with reconnect-forever policies?
I'm using Mule 3.4 CE and DevKit 3.4
Thanks for any help or pointers in the right direction.
In DevKit, in order for your operations to trigger the reconnection mechanism you need to mark the processor with the #ReconnectOn annotation, and specify the exception that will trigger the reconnection.
#Processor
#ReconnectOn(exceptions = {TypeAException.class, TypeBException.class})
public boolean fooProcessor(String param)
throws TypeAException, TypeBException, TypeCException;
In this example the exception of TypeCException will not trigger the reconnection, the others will.
If your #ValidateConnection method returns true, the #Connect won't be called again.

Spring Integration and AMQP: How to gracefully handle deserialization exceptions?

I use RabbitMQ and Spring Integration to handle incoming JSON messages.
The relevant part of the configuration looks something like this:
<amqp:inbound-channel-adapter channel="incomingChannel" queue-names="..."
message-converter="jsonConverter" error-handler="errorHandler"
error-channel="errorChannel" />
I'm using Jackson Databind as the JSON converter.
Sometimes the incoming JSON messages have an incorrect syntax. This results in the following (correct) exception:
org.springframework.amqp.rabbit.listener.ListenerExecutionFailedException: Listener threw exception
Caused by: org.springframework.amqp.support.converter.MessageConversionException: Failed to convert Message content
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_ARRAY token...
The exception is then handled by the errorHandler which simply is a MessagePublishingErrorHandler to errorChannel.
So far so good. The problem is, that the message is still being rejected by the AMQP client, although I am handling it with an error handler. RabbitMQ then redelivers the message over and over. Even configuring a dead letter queue did not help. Any ideas how to handle this scenario correctly?
Exceptions further down the processing (after successful deserialization) are handled just fine: AMQP message acknowledged and error message sent to errorChannel.
Any ideas?
Library versions:
Spring Integration: 3.0.1
Spring Framework: 4.0.2
Jackson Databind: 2.3.1
You can set defaultRequeueRejected=false on the listener container.
The attribute is not currently exposed on the channel adapter, but you can define the container as a <bean... class="...SimpleMessageListenerContainer"/> and inject it into adapter using the listener-container attribute.
Or, use a custom ErrorHandler that throws an AmqpRejectAndDontRequeueException.

"Multiple serializers are not supported" configuration error in NServiceBus 4.0.4 during unit testing

I am trying to unit test message handlers for NServiceBus 4.0.4. The bus is configured to use JSON serializer in the application using the Configure.Serialization.Json(); method call.
Whenever I call the Test.Initialize() method from the unit tests assembly I get the following exception: System.Configuration.ConfigurationErrorsException : Multiple serializers are not supported. Please make sure to only enable one
I tried calling Configure.Serialization.Json() and Serializers.SetDefault<JsonSerialization>() before calling the Test.Initialize() method without any success.
Does anyone know what am I doing wrong? All examples I see on the internet do not mention any Configure calls.
This issue has been reported previously here and looks like it will be fixed in the next NServiceBus build (both 4.0.5 and 4.1.0)
A workaround is to explicitly disable the xml serializer when enabling the json one.
Configure.Serialization.Json();
Feature.Disable<XmlSerialization>(); // hack to make NSB unit tests work