We have recently migrated our EJB 2 application to EJB 3.In EJB2 if some failures in onMessage container will be able to do retry the message on configured number of times however in EJB3 there is no such option.Could someone help on this.
Can we explicitly sleep the thread and do explicitly retry in onMessage?
Thanks in advance .
If you are using #TransactionManagement(value=
TransactionManagementType.CONTAINER) that is container managed
transaction then on exception, message will be retired 10 time
before the message is send to the DLQ.
If you are not using Activemq RA then, following two documents can
be useful to you if you are having Container-Managed Transaction
Redelivery and Exception Handling and Managing Rolled Back,
Recovered, Redelivered, or Expired Messages
If you are using ActiveMq resource adapter, use can use
MaximumRedeliveries Resource Adapter properties
Else, if you want to retry only on specific exception then you can
catch the exception and then send the message back to the same queue
and with this additional property. Activemq consume message after
delay interval Also, set the retry count in the message header
so that you can keep the track of the retries.
Related
Hi I am using a jmslistener annotation to recieve messages from tibco queue. I am DefaultJmsListenerContainer factory with sessionTransacted = true. What I want to do is
When we get a RunTimeException I want to retry the specific message specific no of times(lets say x)
When we get cannot get jdbc connection I want to shutdown the system and want to make sure that this message is sent back to the queue to be redelivered the next time system is brought up.
What I am facing is
When I am setting sessionTransacted as true and I am throwing a RunTimeException the message is redelivered indefinitely . How can I set this configuration to redeliver the message only x times.( I have tried using message header property JMSXDeliveryCount but that does not give me the correct no of times a specific message is redelivered.)
I tried shutting down the system using System.exit(1) but this leads to deadlock and application hangs. I added another piece of code where I am shutting down the application in a different thread and making sure if in between the shutting down of the container another message is read by the listener I throw a RunTimeException so that I am able to get that message again once my system is brought up. However what I want is the 1st message for which we did not get the jdbc connection to be redelivered and no other messages to be read when I stop the container.How can we achieve this.
I sometimes get the error shutting down ExecutorService and then Consumer stopped. Kafka event is processed again, but the duplication appears, as this event is already processed until storing data. I have fixed the duplication with idempotence. But is there a way to prevent this shut down?
The properties of ExponentialBackOffPolicy:
backOffPolicy.setMaxInterval(60000);
backOffPolicy.setMultiplier(2.0);
backOffPolicy.setInitialInterval(1000);
simpleRetryPolicy.setMaxAttempts(60);
It is because you have a large retry interval and the consumer thread is blocked; retry in the listener adapter is deprecated now that the error handlers support back off and exception classification. The error handlers are also able to exit the retry whenever the container is stopped.
You use a suitably configured DefaultErrorHandler (2.8 and later) or a SeekToCurrentErrorHandler for earlier versions (versions before 2.7.10 are no longer supported for OSS users).
I'm trying to interrupt current thread if http request times out. I have setup PlatformTransactionManager for Kafka Transactions as a bean. I'm using #Transactional annotation at method level. We are publishing message in 3 topics. After publishing message in first topic I'm putting Thread.sleep(5000) and current thread is interrupting from filter if execution takes more than 6 seconds. So here call is getting interrupted but message is getting published to Kafka. We are just producing the message. We are not consuming any message but able to see message in our internal Kafka Inspection Tool. We are using KafkaTemplate.send() to send message.
Producer records are always written to the log, even if rolled back. There is a special record in the slot following the published record(s) to indicate whether the transaction was committed or rolled back.
Consumers' isolation.level is read_uncommitted by default; you need to set it to read_committed to avoid seeing rolled-back records.
https://kafka.apache.org/documentation/#consumerconfigs_isolation.level
I want to understand a java program and need to modify which was developed using jms spring framework. Typically it has JMS receiver & sender, it receives a message from request queue and will invoke a job (another java program) once the job is completed the sender will send response to response queue. Have couple of questions which are below,
The request message is not deleted until response posted into response queue successfully. How its been achieved what is the logic behind it.
I want to write a functionality of writing response into flat file when sender fails to send message (by catching JMS exception). Once the sender queue is up and running i will read flat file and will send responses. The reason i need is because its involved in job processing could be in hours if job failed then input message will be read again by receiver. I want to avoid duplicate processing. Please suggest your ideas here.
Without seeing the configuration it's hard to answer these questions, but best guess is that #1 is because the app is using a transactional session. This means all updates on that session are not completed until the transaction is committed.
Just catch the exception and write the data; as long as the transaction commits (because you caught the exception) the input message will be removed.
Is it possible to manage connection timeouts or errors in a MessageDrivenBean?
You can make the factory to retry connecting a certain number of times but... is it possible to make some actions each time that a reconnection retrial is neccesary? Is it possible to register an ExceptionListener into the MessageDrivenBean's connection somehow?
Thanks a lot.
Finally I wasn't able to do this but I changed jmsjra to JMSJCA that fits better my needings. JMSJCA is included in Glassfish ESB project.
You can always have some sort of error topic or queue that you can post the exception to from your MDB. Including the correlationID in the error message to synchronize with the original message if that is desired.