Skip to content

Commit

Permalink
Merged PR 929764: Add ConnectionDeviceId and ConnectionModuleId to am…
Browse files Browse the repository at this point in the history
…qp outgoing messages

Outgoing messages for modules should contain ConnectionDeviceId and ConnectionModuleId properties indicating the source of the message. This already works for Mqtt. This PR adds support fo that on Amqp.
This also needed a corresponding change on the SDK side, here is the PR for that - Azure/azure-iot-sdk-csharp#537
  • Loading branch information
varunpuranik committed Jun 28, 2018
1 parent 31468a1 commit e636135
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,16 @@ public AmqpMessage FromMessage(IMessage message)
amqpMessage.MessageAnnotations.Map[Constants.MessageAnnotationsInputNameKey] = inputName;
}

if (message.SystemProperties.TryGetNonEmptyValue(SystemProperties.ConnectionDeviceId, out string connectionDeviceId))
{
amqpMessage.MessageAnnotations.Map[Constants.MessageAnnotationsConnectionDeviceId] = connectionDeviceId;
}

if (message.SystemProperties.TryGetNonEmptyValue(SystemProperties.ConnectionModuleId, out string connectionModuleId))
{
amqpMessage.MessageAnnotations.Map[Constants.MessageAnnotationsConnectionModuleId] = connectionModuleId;
}

if (message.SystemProperties.TryGetNonEmptyValue(SystemProperties.MessageSchema, out string messageSchema))
{
amqpMessage.ApplicationProperties.Map[Constants.MessagePropertiesMessageSchemaKey] = messageSchema;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@ public static class Constants
public const string MessagePropertiesOutputNameKey = "iothub-outputname";
public const string MessagePropertiesMethodNameKey = "IoThub-methodname";
public const string MessageAnnotationsInputNameKey = "x-opt-input-name";
public const string MessageAnnotationsConnectionDeviceId = "iothub-connection-device-id";
public const string MessageAnnotationsConnectionModuleId = "iothub-connection-module-id";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ public void FromMessageTest_AllProperties()
string operation = "foo";
string inputName = "inputName";
string outputName = "outputName";
string connectionDeviceId = "edgeDevice1";
string connectionModuleId = "module1";

var systemProperties = new Dictionary<string, string>
{
Expand All @@ -253,7 +255,9 @@ public void FromMessageTest_AllProperties()
[SystemProperties.CreationTime] = creationTime,
[SystemProperties.Operation] = operation,
[SystemProperties.InputName] = inputName,
[SystemProperties.OutputName] = outputName
[SystemProperties.OutputName] = outputName,
[SystemProperties.ConnectionDeviceId] = connectionDeviceId,
[SystemProperties.ConnectionModuleId] = connectionModuleId
};

var properties = new Dictionary<string, string>
Expand Down Expand Up @@ -294,6 +298,8 @@ byte[] GetMessageBody(AmqpMessage sourceMessage)
Assert.Equal(lockToken, amqpMessage.MessageAnnotations.Map[Amqp.Constants.MessageAnnotationsLockTokenName]);
Assert.Equal(sequenceNumber, amqpMessage.MessageAnnotations.Map[Amqp.Constants.MessageAnnotationsSequenceNumberName]);
Assert.Equal(inputName, amqpMessage.MessageAnnotations.Map[Amqp.Constants.MessageAnnotationsInputNameKey]);
Assert.Equal(connectionDeviceId, amqpMessage.MessageAnnotations.Map[Amqp.Constants.MessageAnnotationsConnectionDeviceId]);
Assert.Equal(connectionModuleId, amqpMessage.MessageAnnotations.Map[Amqp.Constants.MessageAnnotationsConnectionModuleId]);

Assert.Equal(messageSchema, amqpMessage.ApplicationProperties.Map[Amqp.Constants.MessagePropertiesMessageSchemaKey]);
Assert.Equal(creationTime, amqpMessage.ApplicationProperties.Map[Amqp.Constants.MessagePropertiesCreationTimeKey]);
Expand Down

0 comments on commit e636135

Please sign in to comment.