示例#1
0
        private string SendTestMessageToQueue(bool isSync)
        {
            try
            {
                //ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Http;
                //var client = QueueClient.CreateFromConnectionString(_connectionString, UnderwriteQueueName);
                var client = QueueClient.CreateFromConnectionString(_connectionString, AppConstants.RequestQueueNameUnderwrite);

                TimeZoneInfo easternZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
                DateTime timeStamp = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, easternZone);

                var dto = new UnderwriteRequestDto
                {
                    //Name = "Spongebob + " + DateTime.Now.ToString("h:mm:ss.fff tt"),
                    Name = "Eddie: " + timeStamp.ToString("h:mm:ss.fff tt"),
                    Age = 10,
                    City = "Bikini Bottom"
                };

                var ser = new DataContractSerializer(typeof(UnderwriteRequestDto));
                var msg = new BrokeredMessage(dto, ser);
                client.Send(msg);

                //msg.Properties["mydata"] = "Hello world";
                //client.Send(msg);

                Trace.TraceWarning("Client() - send message");
                return string.Format("Success!    timestamp: {0}",  DateTime.Now.ToString("hh:mm:ss.fff tt"));
            }
            catch (Exception ex)
            {
                return "Error.  Exception: " + ex.Message + "   " + DateTime.Now.ToString("G");
            }
        }
示例#2
0
        public void TestMethod1()
        {
            UnderwriteRequestDto dto = new UnderwriteRequestDto
            {
                Name = "test-name",
                Age = 30
            };
            _underwriteQueue.ProcessMessage(dto);

            Assert.IsNotNull(dto);
        }
示例#3
0
        public UnderwriteResponseDto ProcessMessage(UnderwriteRequestDto requestDto)
        {
            try
            {
                Thread.Sleep(TimeSpan.FromSeconds(3));

                return new UnderwriteResponseDto {Status = 0, StatusMessage = "success"};
            }
            catch (Exception ex)
            {
                Trace.WriteLine("ERROR ** Service Bus message: " + ex.Message);
                return new UnderwriteResponseDto {Status = 1, StatusMessage = ex.Message};
            }
        }