Skip to content

How to Peek And Lock a message in my Spring Boot Application using spring-cloud-azure-starter-servicebus-jms? #37834

Open
@utkarshk8

Description

@utkarshk8

Hey guys so the requirement that I have right now is to setup a Queue Listener Spring Boot Application and I am using
spring-cloud-azure-starter-servicebus-jms for that, but the problem is the default setup mentioned here deletes the message from the queue once I receive it i.e its a destructive read.

My code right now is really simple:
Application name is QueuelistenerApplication

It only contains one file right now i.e QueuelistenerApplication.java with the following code:

package com.queue.listener.queuelistener;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jms.DefaultJmsListenerContainerFactoryConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.jms.annotation.EnableJms;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
import org.springframework.jms.config.JmsListenerContainerFactory;

import jakarta.jms.ConnectionFactory;

@SpringBootApplication
@EnableJms
public class QueuelistenerApplication {
	private static final String QUEUE_NAME = "test";

	public static void main(String[] args) {
		SpringApplication.run(QueuelistenerApplication.class, args);
	}

	@JmsListener(destination = QUEUE_NAME, containerFactory = "jmsListenerContainerFactory")
	public void receiveMessage(String message) {
			System.out.println("Message received: {}" + message);
	}

	

}

Now I don't want the message to be deleted from the Queue once I've consumed it, Instead what I want is to Peek the Message and Lock it, then do my operations and IF the operations are successful then I can manually acknowledge the message, but IF the operations fails then I want the message to be returned to the Queue. How can I achieve that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    ClientThis issue points to a problem in the data-plane of the library.azure-springAll azure-spring related issuesazure-spring-jmsIssues related to Spring JMS.customer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-team-attentionWorkflow: This issue needs attention from Azure service team or SDK teamquestionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

    Type

    No type

    Projects

    Status

    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions