question

DeepanshuGoyal-7478 avatar image
0 Votes"
DeepanshuGoyal-7478 asked PramodValavala-MSFT commented

How to Send and Receive Product Java class Object to and from Azure Queue.

@Getter @Setter @NoArgsConstructor @AllArgsConstructor
public class AzureQueueProductRequest {
private List<AzureQueueProduct> products;
private Long languageId;
@Enumerated(EnumType.STRING)
private ApprovalStatus approvalStatus;

 @Override
 public String toString() {
     return "AzureQueueProductRequest{" +
             "products=" + products +
             ", languageId=" + languageId +
             ", approvalStatus=" + approvalStatus +
             '}';
 }

}

I want to send and receive this type of object to azure queue. Please help me with this.

azure-service-bus
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@DeepanshuGoyal-7478 Like Mayank mentioned in his answer, it's better to serialize to JSON and deserialize it back into an object on both ends of the queue. Using a custom serialize format like your code would require you to code your own deserializer as well, which isn't ideal or even required in most cases.

For Java, Jackson and GSON are popular options.


0 Votes 0 ·

1 Answer

MayankBargali-MSFT avatar image
0 Votes"
MayankBargali-MSFT answered

@DeepanshuGoyal-7478 You can send any type of content (string, objects, bytes, list, etc) to the service bus queue/topic. Whatever you send to the service bus queue/topic it will receive the same at your consumer application. It will depend upon how you are sending/receiving the content i.e. Serialization and Deserialization of the content. You can convert your class object to JSON object and send the JSON string as the message content and at the receiver end the receiving application should know how to Deserialization the JSON string to your defined class.

The query is more towards the conversion of an object to JSON and there are many java libraries available for the conversion of object to JSON and you can refer to some of the third-party documents which help you how you can convert the same and there are many articles/document available on the conversion.
https://www.javatpoint.com/convert-java-object-to-json
https://www.tabnine.com/blog/how-to-convert-a-java-object-into-a-json-string/

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.