get only first message

sachiek
sachiek Member Posts: 7
edited May 2021 in General Discussions #1

Hi,
I want to receive only the first message with property in a Queue.
How to get this? Will this utility will help ?
./sdkperf_jms.sh
Or any other choice ?
Saw this article..Any hint - on how to re-write to receive only first message?
https://tutorials.solace.dev/jcsmp/topic-to-queue-mapping/
These messages are now on your queue. You can validate this through SolAdmin by inspecting the queue. Now receive the messages using a flow consumer as outlined in detail in previous tutorials.

ConsumerFlowProperties flow_prop = new ConsumerFlowProperties();
flow_prop.setEndpoint(queue);
Consumer cons = session.createFlow(new SimplePrintingMessageListener(), flow_prop);
cons.start();

try {
    latch.await(); // block here until message received, and latch will flip
} catch (InterruptedException e) {
    System.out.println("I was awoken while waiting");
}
Tagged:

Answers

  • Tamimi
    Tamimi Member, Administrator, Employee Posts: 538 admin

    Hey @sachiek welcome to the community and congrats on your first post! Just a quick posting tip, you can use ``` to encapsulate any code block for easier formatting. I have edited your post.

  • Aaron
    Aaron Member, Administrator, Moderator, Employee Posts: 634 admin

    Hi @sachiek . So you only want to receive a single message off a queue? And then what? Disconnect? May I ask what the use case is?

    SdkPerf tools will generally try to receive as many messages off a queue as fast as possible, so probably not the best tool there.

    If you want to write some code, and very tightly control the number of messages you receive, you could use a blocking Flow Session, where you pass null into the createFlow() method.

    OR perhaps I've misread you, and you want to choose the first message off a queue that has a certain property..??

  • sachiek
    sachiek Member Posts: 7

    Yes, get first message off a queue and exit.

  • sachiek
    sachiek Member Posts: 7

    @Aaron said:
    Hi @sachiek . So you only want to receive a single message off a queue? And then what? Disconnect? May I ask what the use case is?

    SdkPerf tools will generally try to receive as many messages off a queue as fast as possible, so probably not the best tool there.

    If you want to write some code, and very tightly control the number of messages you receive, you could use a blocking Flow Session, where you pass null into the createFlow() method.

    OR perhaps I've misread you, and you want to choose the first message off a queue that has a certain property..??

    I also trying SEMP API - will update by tomorrow. Right now only able to pull messages i.e first 10. But not able to validate if there is first message in that messages pulled. Will further drill down by tomorrow.

  • sachiek
    sachiek Member Posts: 7
    edited May 2021 #6

    "curl -X GET -u $user:$password $urlip:80/SEMP/v2/monitor/msgVpns/$vpn/queues/$queueName/msgs -H \"content-type: application/json\""
    Is there any option to limit this to get only first message in this SEMP API ? This one by default able to only give 10 messages.

  • sachiek
    sachiek Member Posts: 7

    Also any clue on extract message body of that first message - after finally getting that message id?
    Or should I be able to do this by custom Java code? :)

  • amackenzie
    amackenzie Member, Employee Posts: 268 Solace Employee

    SEMP is not a messaging API, it's an admin API and has no access to the message bodies.
    @Aaron asked about your use case for only wanting 1 message. One of the use cases the broker supports is a queue acting as a Last Value Queue (LVQ) where the queue depth is 0 and therefore there is always only the last message published to the queue. So if that suits your use case, you could implement a LVQ and any consumer would only get a single message.
    https://docs.solace.com/PubSub-Basics/Endpoints.htm#LVQs

  • sachiek
    sachiek Member Posts: 7

    @amackenzie @Aaron - Had used custom Java class to achieve this. Thank you.

  • sachiek
    sachiek Member Posts: 7

    @sachiek said:
    @amackenzie @Aaron - Had used custom Java class to achieve this. Thank you.

    Yes, only first message.

  • himanshu
    himanshu Member, Employee Posts: 67 Solace Employee

    @sachiek - what's the usecase for only getting the first message?