Ejemplo n.º 1
0
        public async Task Send_SendsMessageToServiceBus()
        {
            var id         = Guid.NewGuid();
            var serializer = new JsonMessageSerializer();
            var encoder    = new Utf8Encoder();
            var messenger  = new ServiceBusDomainMessenger(
                new [] { new GlobalUserPropertyStrategy("Id") },
                serializer, encoder, _fixture.Sender);

            var client = _fixture.CreateClient(id);

            TestDomainEvent domainEvent = null;

            client.RegisterMessageHandler((msg, token) =>
            {
                var json    = System.Text.Encoding.UTF8.GetString(msg.Body);
                domainEvent = serializer.DeserializeObject <TestDomainEvent>(json);

                return(Task.CompletedTask);
            }, new MessageHandlerOptions(args => Task.CompletedTask)
            {
                MaxConcurrentCalls = 1,
                AutoComplete       = false
            });

            await messenger.SendAsync(new TestDomainEvent(id));

            while (domainEvent?.Id != id)
            {
                Thread.Sleep(2000);
            }

            domainEvent.Id.Should().Be(id);
        }
Ejemplo n.º 2
0
        internal static Dictionary <string, string> ToDictionary(this string str)
        {
            if (String.IsNullOrEmpty(str))
            {
                return(new Dictionary <string, string>());
            }

            return((Dictionary <string, string>)Serializer.DeserializeObject(str, typeof(Dictionary <string, string>)));
        }
        static Dictionary <string, string> ExtractHeaders(IMessage message)
        {
            if (!message.PropertyExists(Constants.NSB_HEADERS))
            {
                return(new Dictionary <string, string>());
            }

            return(Serializer.DeserializeObject <Dictionary <string, string> >(
                       message.GetStringProperty(Constants.NSB_HEADERS)));
        }
        public static ServiceInfo LoadFromDisk(string serviceName)
        {
            var ser = new JsonMessageSerializer();

            var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, serviceName + ".json");
            if (File.Exists(path))
            {
                var data = File.ReadAllBytes(path);
                return ser.DeserializeObject<ServiceInfo>(data);
            }
            else
            {
                return null;
            }
        }