spring-bootazureazureservicebusazure-servicebus-topics

How to setup java spring boot application to send message to Azure service bus Topic


I am asking this question here to get help from Microsoft or community

I want to send messages to a topic using spring boot application

The azure page is service bus

My app properties

spring.cloud.azure.servicebus.namespace=<<some name>> 
spring.cloud.azure.servicebus.entity-name=<<some topic>> 

spring.cloud.azure.servicebus.processor.subscription-name=<<somesub>> 

spring.cloud.azure.servicebus.entity-type=topic

Error:

Caused by: java.lang.IllegalArgumentException: Subscription cannot be null.

My code has the dependency management , spring-cloud-azure-starter-servicebus

The config class as mentioned in the pages - ServiceBusProcessorClientConfiguration

and the bootstrap class - ServiceBusQueueApplication

(I prefer to have a sender and a receiver in 2 different apps. Not like PING-PONG in the same program. May be I want to see/consume message in a logic app )

what am I missing ? How to send message with properties (see attached)

EDIT:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serviceBusReceiverClientBuilder' defined in class path resource [com/azure/spring/cloud/autoconfigure/implementation/servicebus/AzureServiceBusConsumerClientConfiguration$NoneSessionConsumerClientConfiguration.class]: Failed to instantiate [com.azure.messaging.servicebus.ServiceBusClientBuilder$ServiceBusReceiverClientBuilder]: Factory method 'serviceBusReceiverClientBuilder' threw exception with message: Subscription cannot be null.
    
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.azure.messaging.servicebus.ServiceBusClientBuilder$ServiceBusReceiverClientBuilder]: Factory method 'serviceBusReceiverClientBuilder' threw exception with message: Subscription cannot be null.
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:177) ~[spring-beans-6.1.6.jar:6.1.6]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:644) ~[spring-beans-6.1.6.jar:6.1.6]
    ... 18 common frames omitted
Caused by: java.lang.IllegalArgumentException: Subscription cannot be null.
    at org.springframework.util.Assert.notNull(Assert.java:172) ~[spring-core-6.1.6.jar:6.1.6]
    at com.azure.spring.cloud.service.implementation.servicebus.factory.ServiceBusReceiverClientBuilderFactory.configureService(ServiceBusReceiverClientBuilderFactory.java:54) ~[spring-cloud-azure-service-5.11.0.jar:5.11.0]
    at com.azure.spring.cloud.service.implementation.servicebus.factory.ServiceBusReceiverClientBuilderFactory.configureService(ServiceBusReceiverClientBuilderFactory.java:15) ~[spring-cloud-azure-service-5.11.0.jar:5.11.0]
    at com.azure.spring.cloud.core.implementation.factory.AbstractAzureServiceClientBuilderFactory.build(AbstractAzureServiceClientBuilderFactory.java:128) ~[spring-cloud-azure-core-5.11.0.jar:5.11.0]
    at com.azure.spring.cloud.autoconfigure.implementation.servicebus.AzureServiceBusConsumerClientConfiguration$NoneSessionConsumerClientConfiguration.serviceBusReceiverClientBuilder(AzureServiceBusConsumerClientConfiguration.java:70) ~[spring-cloud-azure-autoconfigure-5.11.0.jar:5.11.0]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:140) ~[spring-beans-6.1.6.jar:6.1.6]
    ... 19 common frames omitted

POM:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>azureservicebus</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>azureservicebus</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>17</java.version>
        <spring-cloud-azure.version>5.11.0</spring-cloud-azure.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>com.azure.spring</groupId>
            <artifactId>spring-cloud-azure-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>com.azure.spring</groupId>
            <artifactId>spring-cloud-azure-starter-servicebus</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.azure.spring</groupId>
                <artifactId>spring-cloud-azure-dependencies</artifactId>
                <version>${spring-cloud-azure.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

enter image description here


Solution

  • Microsoft has provided an answer and updated the documentation

    Add this property and the service bus topic works

    spring.cloud.azure.servicebus.consumer.subscription-name=<same as processor subscription>
    

    and about filter messages, send data with application properties and the rule works

    message.getApplicationProperties().put("status", data.getStatus());
    senderClient.sendMessage(message);