You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

51 lines
1.3 KiB

  1. using System;
  2. using DotNetCore.CAP.Abstractions;
  3. using DotNetCore.CAP.Models;
  4. using Newtonsoft.Json;
  5. namespace Sample.RabbitMQ.SqlServer
  6. {
  7. public class MessageContent : CapMessage
  8. {
  9. [JsonProperty("id")]
  10. public override string Id { get; set; }
  11. [JsonProperty("createdTime")]
  12. public override DateTime Timestamp { get; set; }
  13. [JsonProperty("msgBody")]
  14. public override string Content { get; set; }
  15. [JsonProperty("callbackTopicName")]
  16. public override string CallbackName { get; set; }
  17. }
  18. public class MyMessagePacker : IMessagePacker
  19. {
  20. private readonly IContentSerializer _serializer;
  21. public MyMessagePacker(IContentSerializer serializer)
  22. {
  23. _serializer = serializer;
  24. }
  25. public string Pack(CapMessage obj)
  26. {
  27. var content = new MessageContent
  28. {
  29. Id = obj.Id,
  30. Content = obj.Content,
  31. CallbackName = obj.CallbackName,
  32. Timestamp = obj.Timestamp
  33. };
  34. return _serializer.Serialize(content);
  35. }
  36. public CapMessage UnPack(string packingMessage)
  37. {
  38. return _serializer.DeSerialize<MessageContent>(packingMessage);
  39. }
  40. }
  41. }