Skip to content

Commit

Permalink
Adding a method to clone Message and making MessageBody serializable (A…
Browse files Browse the repository at this point in the history
…zure#334)

* Making MessageBody serializable. Also changing version to 1.2.11. (Azure#328)


# Conflicts:
#	azure-servicebus/azure-servicebus.pom
#	pom.xml

* Adding createCopy method to clone a message that was somehow removed in one of the previous merges.
  • Loading branch information
yvgopal authored Feb 14, 2019
1 parent e041e37 commit 44bc61f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -421,4 +421,10 @@ public interface IMessage {
* @see <a href="https://docs.microsoft.com/azure/service-bus-messaging/message-transfers-locks-settlement">Message transfers, locks, and settlement</a>
*/
public UUID getLockToken();

/**
* Creates a shallow copy of this message.
* @return copy of this message
*/
public IMessage createCopy();
}
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,23 @@ public void setMessageBody(MessageBody body)
{
this.messageBody = body;
}

@Override
public IMessage createCopy() {
Message copy = new Message(this.getMessageBody(), this.getContentType());
copy.setProperties(this.getProperties()); // Retain the same properties

copy.setMessageId(this.getMessageId());
copy.setCorrelationId(this.getCorrelationId());
copy.setTo(this.getTo());
copy.setReplyTo(this.getReplyTo());
copy.setLabel(this.getLabel());
copy.setReplyToSessionId(this.getReplyToSessionId());
copy.setSessionId(this.getSessionId());
copy.setScheduledEnqueueTimeUtc(this.getScheduledEnqueueTimeUtc());
copy.setPartitionKey(this.getPartitionKey());
copy.setTimeToLive(this.getTimeToLive());

return copy;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.microsoft.azure.servicebus;

import java.io.Serializable;
import java.util.List;

/**
Expand All @@ -8,8 +9,11 @@
* Client should test for body type before calling corresponding get method.
* Get methods not corresponding to the type of the body return null.
*/
public class MessageBody {
private MessageBodyType bodyType;
public class MessageBody implements Serializable{

private static final long serialVersionUID = 7215009530928988502L;

private MessageBodyType bodyType;
private Object valueData;
private List<List<Object>> sequenceData;
private List<byte[]> binaryData;
Expand Down

0 comments on commit 44bc61f

Please sign in to comment.