Azure Queue trigger not working with Java

753 views Asked by At

I have a spring boot application which will publish message on azure Queue. I have one more azure queueTrigger function written in Java which will listen to the same queue to which spring boot application has published a message. The queueTrigger function not able to detected messages published on queue.

Here is my publisher code

public static void addQueueMessage(String connectStr, String queueName, String message) {
    try {
            // Instantiate a QueueClient which will be
            // used to create and manipulate the queue
            QueueClient queueClient = new QueueClientBuilder()
                                        .connectionString(connectStr)
                                        .queueName(queueName)
                                        .buildClient();
    
            System.out.println("Adding message to the queue: " + message);
    
            // Add a message to the queue
            queueClient.sendMessage(message);
        }  catch (QueueStorageException e) {
            // Output the exception message and stack trace
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
 }

Here is my queueTrigger function app code

@FunctionName("queueprocessor")
public void run(
   @QueueTrigger(name = "message",
                  queueName = "queuetest",
                  connection = "AzureWebJobsStorage") String message,
    final ExecutionContext context
) {
    context.getLogger().info(message);
}

I'm passing same connection-String and queueName, still doesn't work. If i run function on my local machine then it gets triggered but with error error image

1

There are 1 answers

7
krishg On

As the official doc suggests,

Functions expect a base64 encoded string. Any adjustments to the encoding type (in order to prepare data as a base64 encoded string) need to be implemented in the calling service.

Update sender code to send base64 encoded message.

String encodedMsg = Base64.getEncoder().encodeToString(message.getBytes())
queueClient.sendMessage(encodedMsg);