Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Try out an existing microservice

In the java-microservices-aca-lab repository’s src directory, the spring-petclinic-messaging-emulator microservice is already prepared to send messages to an Azure Service Bus namespace. You can add this microservice to your current Spring Petclinic project in the parent pom.xml file, deploy it as an extra microservice in your ACA environment and use this microservice’s public endpoint to send messages to your Service Bus namespace. Test this functionality and inspect whether messages end up in the Service Bus namespace you just created by using the Service Bus Explorer for the visits-requests queue. You can use the following guidance to implement these changes:

Step by step guidance

  1. From the Git Bash window, in the java-microservices-aca-lab repository you cloned locally, navigate to the src directory and use your favorite text editor to open the pom.xml file in the root directory of the cloned repo. you’ll have to uncomment the module for the spring-petclinic-messaging-emulator in the <modules> element at line 26.

     <module>spring-petclinic-messaging-emulator</module>
    
  2. Run a build of the messaging emulator.

    cd ~/workspaces/java-microservices-aca-lab/src
    mvn clean package -DskipTests -rf :spring-petclinic-messaging-emulator
    
  3. Once the build is done, move to the staging-acr directory and create the extra one container app for the messaging emulator.

    export APP_NAME="messaging-emulator"
    cp ../spring-petclinic-$APP_NAME/target/spring-petclinic-$APP_NAME-$VERSION.jar spring-petclinic-$APP_NAME-$VERSION.jar
    sed -i "s|my-service|$APP_NAME|g" Dockerfile
       
    az containerapp create \
      --name $APP_NAME \
      --resource-group $RESOURCE_GROUP \
      --source .  \
      --env-vars APPLICATIONINSIGHTS_CONNECTION_STRING=$AI_CONNECTIONSTRING APPLICATIONINSIGHTS_CONFIGURATION_CONTENT='{"role": {"name": "messaging-emulator"}}' InstrumentationKey=$AI_CONNECTIONSTRING SERVICEBUS_NAMESPACE=$SERVICEBUS_NAMESPACE CLIENT_ID=$CLIENT_ID \
      --registry-server $MYACR.azurecr.io \
      --registry-identity $USER_ID \
      --environment $ACA_ENVIRONMENT \
      --user-assigned $USER_ID \
      --ingress external \
      --target-port 8080 \
      --min-replicas 1 \
      --bind $JAVA_CONFIG_COMP_NAME $JAVA_EUREKA_COMP_NAME \
      --runtime java
       
    sed -i "s|$APP_NAME|my-service|g" Dockerfile
    rm spring-petclinic-$APP_NAME-$VERSION.jar
    
  4. You configured the messaging-emulator with an external ingress. You can go to the portal and check application url for the messaging-emulator container app.
    messaging_emulator_FQDN=$(az containerapp show \
      --resource-group $RESOURCE_GROUP \
      --name messaging-emulator \
      --query properties.configuration.ingress.fqdn \
      -o tsv)
         
    echo $messaging_emulator_FQDN
    
  5. Use a browser window to connect to messaging_emulator_FQDN. This will open up the messaging emulator page.

  6. On the newly open browser page titled Message, enter 1 in the Pet text box and a random text in the Message text box, and then select Submit.

  7. In the Azure Portal, navigate to your resource group and select the Service Bus namespace you deployed in the previous task.

  8. In the navigation menu, in the Entities section, select Queues and then select the visits-requests queue entry.

  9. On the Overview page of the visits-requests queue, verify that the active message count is set to 1.

  10. Select Service Bus Explorer and select Peek from start. This operation allows you to peek at the top messages on the queue, without dequeuing them.

  11. Select the message entry in the queue and review the Message Body section to confirm that its content matches the message you submitted.

You might want to inspect the code of the messaging-emulator microservice. Take a look at:

  • The dependencies for the Service Bus in the pom.xml file.
  • The PetClinicVisitRequestSender and PetClinicMessageResponsesReceiver classes in the service folder. These are the classes that enable sending and receiving of messages to and from a queue using JMS.
  • The PetClinicMessageRequest and PetClinicMessageResponse classes in the entity folder. These are the messages being sent back and forth.
  • The MessagingConfig class in the config folder. This class provides conversion to and from JSON.
  • The AzureServiceBusResource class in the web folder. This class makes use of the above classed to send a message to the Service Bus.

In the next steps you will add similar functionality to the visits service.