Azure Functions Java using ServiceBusQueueOutput to send message with schedule enqueue time

Maciej Bąk 46 Reputation points
2022-10-27T07:48:26.4+00:00

message send to the servicebus can be processed by consumer after some time, simply by setting ScheduledEnqueueTime param. Its easy to achieve this while working on "raw" service bus message ie:

var serviceBusMessage = new ServiceBusMessage(json);  
serviceBusMessage.setScheduledEnqueueTime(someTime);  

but I have azure functions java app, that has:

  @FunctionName("Process-Notifications")  
public void processNotifications(  
    @ServiceBusQueueTrigger(name = "MessageCmd", queueName = "queue_name_notify_cmd_v1", connection = "SBusConn") String messageCmd,  
    @ServiceBusQueueOutput(name = "NotifyForRetry", queueName = "queue_name_notify_cmd__v1", connection = "SBusConn") OutputBinding<String> notifyForRetry,  

sending notification is easy here, I only do:

Map<String, Object> result = mapper.convertValue(json, new TypeReference<>() { });  
  
        String channels = "";  
        if (error instanceof SmsOnlyError) {  
            channels+="sms";  
        }  
        if (error instanceof EmailOnlyError) {  
            channels+="email";  
        }  
        if (error instanceof AllDefinedChannelsError) {  
            channels+="sms, email";  
        }  
  
        properties.put("retry_channels", channels);  
        result.put("UserProperties", properties);  
        result.put("ScheduledEnqueueTime", OffsetDateTime.now(defaultClock).plusMinutes(15).toString());  
  
        JsonNode newJson = mapper.convertValue(result, JsonNode.class);  

hard to find something in docs, maybe someone here can me ?

thanks!

and works fine. But I have no idea how to set ScheduledEnqueueTime there..

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MughundhanRaveendran-MSFT 12,506 Reputation points
    2022-10-31T10:54:59.4+00:00

    Hi @Maciej Bąk ,

    Thanks for reaching out to Q&A forum.

    It appears that the ScheduledEnqueueTime property is not available as a part of the bindings in Java functions. However, I see some references for .net-based functions. I would suggest you to use the Azure Service bus SDK for Java to set the ScheduledEnqueueTime.

    https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus-output?tabs=in-process%2Cextensionv5&pivots=programming-language-java#usage

    Hope this helps! Feel free to reach out to me if you have any queries or concerns.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.