Closed wingsofovnia closed 6 years ago
Hi @wingsofovnia , Thanks for your interest in AWS IoT Device SDK Java. I will create a issue in our backlog and will look into this and fix it in the future release.
Both the incoming message callback and publish completion processing are handed by the client thread pool, and by default, the size of each client's thread pool is 1, so they might be competing the same thread. This could be fixed by adding the following line before connect.
mqttClient.setNumOfClientThreads(2);
@rongsaws right. Anyway, this looks suspicious to me, they should use different pools since they are operations of different purposes. Moreover, setNumOfClientThreads(2);
will introduce a possible race condition in case of multiple listeners with nested publishers. not a fix imho.
Just an FYI for those using this within an SQS Listener in Spring Boot. The same issue arises when the SQS message arrives and you send an IoT publish message. Setting the Number of Client Threads, as suggested by @rongsaws worked to solve the problem.
Thanks for your interest. Please open another thread if you still have problems.
Has it been resolved yet? I use the implementation 'com.amazonaws:aws-java-sdk-iotjobsdataplane:1.11.653'
and have the same problem.
I agree with @wingsofovnia that setNumOfClientThreads(2);
is not fix because I subsribe to a couple of topics and each of them publishes to another topic.
if someone is still needed, we can use forkJoinPool if you don't want to define threads for clients.
ForkJoinPool.commonPool().execute(() -> { call your publish method here})
this should also solve.
Problem
Publishing a message in a response to a message is very typical case but
AWSIotMqttClient#publish
stucks inScheduledThreadPoolExecutor
if it's run insideAWSIotMessage#onMethod
callback forAWSIotMqttClient#subscribe
:Scenario
Expected result
onMessage
callback is called on each message arrival to a 'in' topicActual result:
onMessage
reacts on the first message arrived onlyonMessage
thread is blocked byAwsIotCompletion#get:203
waitScheduledExecutorService
byAbstractAwsIotClient#dispatch
but won't be ever processed.Walkaround
Run a publish method in a separate thread (uncomment sendHelloWordlAsync, comment sendHelloWordlSync).