Search code examples
javaazureservicebusazure-servicebus-queues

Not able to send the message using Azure service bus


Dotnet samples (send/receive) are working fine. From java I am not able to send the message but receiving messages are working fine.

private boolean connectServer()
{
    try {
        if (null != senderClient) return true;
        senderClient = new ServiceBusClientBuilder()
                .connectionString(connectionString)
                .transportType(AmqpTransportType.AMQP_WEB_SOCKETS)
                .sender()
                .queueName(queueName)
                .buildAsyncClient();
        return true;
    }
    catch (Exception ex)
    {
        System.out.println(ex);
        return false;
    }
}



public boolean sendMessage(String message) throws InterruptedException {
    try {
        connectServer();
        senderClient.sendMessage(new ServiceBusMessage(BinaryData.fromString(message)));
        return true;
    }
    catch (Exception ex)
    {
        System.out.println(ex);
        return false;
    }
}

I'm not getting any error. In Azure portal --> Overview. I can see multiple incoming requests but incoming messages are 0.

Azure Portal


Solution

  • Regarding the issue, please refer to the following code

    ServiceBusSenderClient senderClient = new ServiceBusClientBuilder()
                    .connectionString(connectionString)
                    .sender()
                    .queueName(queueName)
                    .buildClient();
    
            ServiceBusMessage message = new ServiceBusMessage("Hello world!");
            senderClient.sendMessage(message);
            System.out.println("Sent  messages to the queue: " + queueName);
    

    enter image description here

    enter image description here