Skip to content

Commit

Permalink
made DataBusAttachment serializable across the board
Browse files Browse the repository at this point in the history
  • Loading branch information
mookid8000 committed Jun 21, 2016
1 parent cc8a4f0 commit aa8a2dc
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -974,6 +974,7 @@
# 0.99.63

* Maintain time of last read access in all data bus storages
* Made `DataBusAttachment` serializable with all currently supported serializers (JSON.NET, Jil, Wire, and Protobuf)

---

Expand Down
4 changes: 4 additions & 0 deletions Rebus.Protobuf/ProtobufSerializer.cs
Expand Up @@ -4,6 +4,7 @@
using System.Runtime.Serialization;
using System.Threading.Tasks;
using ProtoBuf.Meta;
using Rebus.DataBus;
using Rebus.Extensions;
using Rebus.Messages;
using Rebus.Messages.Control;
Expand All @@ -28,6 +29,9 @@ public ProtobufSerializer(RuntimeTypeModel runtimeTypeModel)
var unsubscribeRequestType = _runtimeTypeModel.Add(typeof (UnsubscribeRequest), true);
unsubscribeRequestType.AddField(1, Reflect.Path<UnsubscribeRequest>(r => r.Topic));
unsubscribeRequestType.AddField(2, Reflect.Path<UnsubscribeRequest>(r => r.SubscriberAddress));

var dataBusAttachmentType = _runtimeTypeModel.Add(typeof(DataBusAttachment), true);
dataBusAttachmentType.AddField(1, Reflect.Path<DataBusAttachment>(r => r.Id));
}

public ProtobufSerializer()
Expand Down
7 changes: 6 additions & 1 deletion Rebus.Tests/DataBus/SimpleTest.cs
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -78,7 +79,11 @@ public async Task CanSendBigFile()
// send a message that sends the contents of a file as an attachment
using (var source = File.OpenRead(sourceFilePath))
{
var attachment = await _senderBus.Advanced.DataBus.CreateAttachment(source);
var optionalMetadata = new Dictionary<string, string>
{
{"username", Thread.CurrentPrincipal.Identity.Name }
};
var attachment = await _senderBus.Advanced.DataBus.CreateAttachment(source, optionalMetadata);

await _senderBus.Send(new MessageWithAttachment
{
Expand Down
13 changes: 13 additions & 0 deletions Rebus.Tests/Serialization/BasicSerializationTests.cs
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using NUnit.Framework;
using Rebus.DataBus;
using Rebus.Messages;
using Rebus.Messages.Control;
using Rebus.Serialization;
Expand All @@ -19,6 +20,18 @@ protected override void SetUp()
_serializer = _factory.GetSerializer();
}

[Test]
public async Task CanRoundtripInternalMessages_DataBusAttachment()
{
var message = new DataBusAttachment("bimmelim!!!");

Console.WriteLine("Roundtripping {0}", message.GetType());

var roundtrippedMessage = (DataBusAttachment)await Roundtrip(message);

Assert.That(roundtrippedMessage.Id, Is.EqualTo("bimmelim!!!"));
}

[Test]
public async Task CanRoundtripInternalMessages_SubscribeRequest()
{
Expand Down
9 changes: 8 additions & 1 deletion Rebus/DataBus/DataBusAttachment.cs
Expand Up @@ -26,7 +26,14 @@ public DataBusAttachment(string id)
/// <summary>
/// Gets the ID of the attachment
/// </summary>
public string Id { get; }
public string Id
{
get;
protected set; // protected setter to make the JIL serializer happy
}

// ctor added to make the JIL serializer happy
DataBusAttachment() { }

/// <summary>
/// Opens the attachment for reading, using the data bus of the bus that is handling the current message to read it.
Expand Down

0 comments on commit aa8a2dc

Please sign in to comment.