activemq


message-driven-channel-adapter drops first message after app context startup unless send is called with a delay


I have an integration test for my Spring Integration config, which consumes messages from a JMS topic with durable subscription. For testing, I am using ActiveMQ instead of Tibco EMS.
The issue I have is that I have to delay sending the first message to the endpoint using a sleep call at the beginning of our test method. Otherwise the message is dropped.
If I remove the setting for durable subscription and selector, then the first message can be sent right away without delay.
I'd like to get rid of the sleep, which is unreliable. Is there a way to check if the endpoint is completely setup before I send the message?
Below is the configuration.
Thanks for your help!
<int-jms:message-driven-channel-adapter
id="myConsumer" connection-factory="myCachedConnectionFactory"
destination="myTopic" channel="myChannel" error-channel="errorChannel"
pub-sub-domain="true" subscription-durable="true"
durable-subscription-name="testDurable"
selector="..."
transaction-manager="emsTransactionManager" auto-startup="false"/>
If you are using a clean embedded activemq for the test, the durability of the subscription is irrelevant until the subscription is established. So you have no choice but to wait until that happens.
You could avoid the sleep by sending a series of startup messages and only start the real test when the last one is received.
EDIT
I forgot that there is a methodisRegisteredWithDestination() on the DefaultMessageListenerContainer.
Javadocs...
/**
* Return whether at least one consumer has entered a fixed registration with the
* target destination. This is particularly interesting for the pub-sub case where
* it might be important to have an actual consumer registered that is guaranteed
* not to miss any messages that are just about to be published.
* <p>This method may be polled after a {#link #start()} call, until asynchronous
* registration of consumers has happened which is when the method will start returning
* {#code true} – provided that the listener container ever actually establishes
* a fixed registration. It will then keep returning {#code true} until shutdown,
* since the container will hold on to at least one consumer registration thereafter.
* <p>Note that a listener container is not bound to having a fixed registration in
* the first place. It may also keep recreating consumers for every invoker execution.
* This particularly depends on the {#link #setCacheLevel cache level} setting:
* only {#link #CACHE_CONSUMER} will lead to a fixed registration.
*/
We use it in some channel tests, where we get the container using reflection and then poll the method until we are subscribed to the topic.
/**
* Blocks until the listener container has subscribed; if the container does not support
* this test, or the caching mode is incompatible, true is returned. Otherwise blocks
* until timeout milliseconds have passed, or the consumer has registered.
* #see DefaultMessageListenerContainer#isRegisteredWithDestination()
* #param timeout Timeout in milliseconds.
* #return True if a subscriber has connected or the container/attributes does not support
* the test. False if a valid container does not have a registered consumer within
* timeout milliseconds.
*/
private static boolean waitUntilRegisteredWithDestination(SubscribableJmsChannel channel, long timeout) {
AbstractMessageListenerContainer container =
(AbstractMessageListenerContainer) new DirectFieldAccessor(channel).getPropertyValue("container");
if (container instanceof DefaultMessageListenerContainer) {
DefaultMessageListenerContainer listenerContainer =
(DefaultMessageListenerContainer) container;
if (listenerContainer.getCacheLevel() != DefaultMessageListenerContainer.CACHE_CONSUMER) {
return true;
}
while (timeout > 0) {
if (listenerContainer.isRegisteredWithDestination()) {
return true;
}
try {
Thread.sleep(100);
} catch (InterruptedException e) { }
timeout -= 100;
}
return false;
}
return true;
}

Related Links

Install a package from tarball using puppet
Can the ActiveMQ Web Console Be Customized?
Order dependency of ActiveMQ in case of ServiceMix-Shutdown
Get dump of fuse activemq messages
Set Different Re-delivery Policy for each message in Queue of ActiveMQ 5.14
How does ActiveMQ AMQ_SCHEDULED_DELAY message works?
How long is message locked for specified subscriber in ActiveMQ using STOMP?
KahaDB not cleaning up journal log files AMQ 5.13.3
HornetQ support in JBoss7 eap
How do I make my ActiveMQ broker drop offline durable subscribers
ActiveMQ: How to merge the schedulerdb of two ActiveMQ brokers
activemq message are not consumed by remote broker
get all queue names for activemq in java
ActiveMQ - java.io.EOFException
connect to active mq from spark streaming
Can you subscribe and publish to the same ActiveMQ topic

Categories

HOME
ionic2
apple-push-notifications
applescript
qc
code-formatting
consul
vue-resource
turbojpeg
sentry
fasm
locationmanager
amazon-emr
erd
sap-fiori
phpstorm-2017.1
orc
responsivevoice
sonata
exe
robolectric
jitsi
high-availability
list-comprehension
running-object-table
marquee
substance
actframework
seafile-server
winrm
buildforge
keyboard-layout
bluemixtools
ftp-server
twilio-php
cheat-engine
imgur
grails-spring-security
plane
uipickerview
optionaldataexception
contactless-smartcard
morphline
git-tfs
nomad
ipp-protocol
common-table-expression
absolute
rightnow-crm
karabiner
punctuation
winmerge
connect-direct
dblink
kendo-editor
kendo-treeview
cognos-tm1
prefetch
gawk
yargs
cefpython
xmlbeans
dmarc
wininet
fiber
adp
juniper-network-connect
dsa
ambiguity
pythonxy
espresso
alwayson
kefir.js
phpredis
deque
innerhtml
r.java-file
fiware-bosun
mojo
createfile
device-admin
berkeley-db-xml
coding-efficiency
redpitaya
zend-search-lucene
boolean-algebra
oxygene
lync-2010
meteorite
jmenubar
mousemotionlistener
postgres-xc
statechart
jbox2d
onconfigurationchanged
websphere-6.1
uipangesturerecognizer
cewolf
jmenu
turbine
gaelyk
mygeneration
android-input-method
oracle-pro-c
html-components
main-method
activex-exe
levels

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App