Delay Delivery Queue Property with New Java API

Sreekanth
Sreekanth Member Posts: 13 ✭✭

Hello,

I am creating a Solace consumer using the new Java API with the "create resource" strategy. My application will create a queue if it does not already exist. I would like to add the capability in my code to set delayed delivery, which we are currently configuring through the Solace dashboard/CLI. Is there a way to achieve this using the new Java API SDK?

Comments

  • murat
    murat Member, Employee Posts: 25 Solace Employee

    Hi @Sreekanth, the only way to set delayed delivery or other endpoint properties via the Java API would be to use endpoint templates. You can find more information on them here:

    https://docs.solace.com/Messaging/Guaranteed-Msg/Configuring-Endpoint-Templates.htm

    Hope that helps!

  • Kevin
    Kevin Member Posts: 5

    Hi there!

    Yes, you can set delayed delivery for your queues using the new Java API SDK. When creating a queue, you can specify the deliveryDelay property in the queue configuration. This allows you to set the desired delay directly in your code instead of relying solely on the Solace dashboard or CLI.

    Here's a quick example of how you might implement this:

    import com.solacesystems.jms.SolConnectionFactory;
    import com.solacesystems.jms.SolQueue;
    import com.solacesystems.jms.SolSession;

    SolConnectionFactory connectionFactory = new SolConnectionFactory();
    connectionFactory.setHost("your-solace-host");
    connectionFactory.setVPN("your-vpn");
    connectionFactory.setUsername("your-username");
    connectionFactory.setPassword("your-password");

    SolSession session = connectionFactory.createQueueSession(false, SolSession.AUTO_ACKNOWLEDGE);

    // Check if the queue exists and create it if it doesn't
    String queueName = "your-queue-name";
    SolQueue queue = session.createQueue(queueName);

    int deliveryDelay = 5000; // delay in milliseconds
    queue.setDeliveryDelay(deliveryDelay);

    session.createProducer(queue).send(yourMessage); // Send your message to the queue

    session.close();
    connectionFactory.close();

    Make sure to adjust the deliveryDelay value as needed. If you have any specific questions or need further assistance with your implementation, feel free to ask!