public void SendMessage(Message message)
 {
     try
     {
         if (leadScoreMessages.Contains(message.LeadScoreConditionType))
         {
             SetLeadScoreMessage(message);
         }
         if (automationMessages.Contains(message.LeadScoreConditionType))
         {
             Logger.Current.Informational("Sending message. " + message.ToString());
             TopicClient topicClient = TopicClient.Create(topicName);
             Send(topicClient, message);
         }
     }
     catch (MessagingException ex)
     {
         if (!ex.IsTransient)
         {
             Logger.Current.Error("Non-Transient error occurred while sending the message." + message.ToString());
             throw;
         }
         else
         {
             HandleTransientErrors(ex, message);
         }
     }
 }
Exemplo n.º 2
0
        private void SendSettingsToSubs(AutoResetEvent fileChangeEvent)
        {
            do
            {
                if (fileChangeEvent.WaitOne())
                {
                    var           fileNameXml  = ConfigurationManager.AppSettings["SettingsFile"];
                    XmlSerializer deserializer =
                        new XmlSerializer(typeof(ClientSetting));

                    if (TryOpen(fileNameXml, 3))
                    {
                        TextReader reader = new StreamReader(fileNameXml);

                        object obj = deserializer.Deserialize(reader);
                        reader.Close();

                        var clientSetting = obj as ClientSetting;
                        var client        = TopicClient.Create(ClientSettingstopic);
                        client.Send(new BrokeredMessage(clientSetting));
                        client.Close();
                    }
                }
            } while (WaitHandle.WaitAny(new WaitHandle[] { _stopEvent, fileChangeEvent }, 1000) != 0);
        }
        public void SendMessageWithOutTracking(Message message)
        {
            try
            {
                Logger.Current.Informational("Sending message. " + message.ToString());
                TopicClient topicClient = TopicClient.Create(topicName);

                var             serializedMessage = JsonConvert.SerializeObject(message);
                BrokeredMessage brokeredMessage   = new BrokeredMessage(serializedMessage);
                brokeredMessage.Properties.Add("LeadScoreConditionType", message.LeadScoreConditionType);
                brokeredMessage.ContentType             = message.GetType().AssemblyQualifiedName;
                brokeredMessage.ScheduledEnqueueTimeUtc = DateTime.UtcNow;

                Task send = topicClient.SendAsync(brokeredMessage).ContinueWith(t =>
                {
                    Logger.Current.Informational("Message sent successfully. ");
                });

                Task.WaitAll(send);
            }
            catch (MessagingException ex)
            {
                if (!ex.IsTransient)
                {
                    Logger.Current.Error("Non-Transient error occurred while sending the message." + message.ToString());
                    throw;
                }
                else
                {
                    HandleTransientErrors(ex, message);
                }
            }
        }
Exemplo n.º 4
0
        private void ChangeSettingCallBack(object sender, FileSystemEventArgs e)
        {
            bool accessed = false;

            while (!accessed)
            {
                try
                {
                    this.infoLog.Info("Setting file was changed");
                    XmlSerializer  f         = new XmlSerializer(typeof(StateModelData));
                    StateModelData stateData = null;
                    using (FileStream fs = new FileStream(this.settingsDir + "\\" + ConfigurationManager.AppSettings["settings"], FileMode.OpenOrCreate))
                    {
                        stateData = (StateModelData)f.Deserialize(fs);
                    }

                    var client = TopicClient.Create(ConfigurationManager.AppSettings["topic"]);
                    client.Send(new BrokeredMessage(stateData));
                    client.Close();
                    this.infoLog.Info("New setting was sent to all subscribers");
                    accessed = true;
                }
                catch (IOException ex)
                {
                    this.errorLog.Error(ex, "Cannot read setting file");
                    Task.Delay(2000);
                }
            }
        }
Exemplo n.º 5
0
        protected void PushMessages(IEnumerable <TestMessage> messages)
        {
            CreateSubscription();

            TopicClient.Create(TopicPath)
            .SendBatch(GetBrokeredMessages(messages));
        }
Exemplo n.º 6
0
        public QueueServer(string saveFilePath, string fileQueueName, string statusQueueName)
        {
            _fileQueueName   = fileQueueName;
            _statusQueueName = statusQueueName;
            _saveFilePath    = saveFilePath;

            CreateQueue(_fileQueueName);
            CreateQueue(_statusQueueName);

            NamespaceManager namespaceManager = NamespaceManager.Create();

            _topicName = ServerConstants.SettingTopicName;


            if (!namespaceManager.TopicExists(_topicName))
            {
                namespaceManager.CreateTopic(new TopicDescription(_topicName)
                {
                    EnablePartitioning = false
                });
            }

            _topicClient = TopicClient.Create(_topicName);
            FileSystemWatcher watcher = new FileSystemWatcher();

            watcher.Path                = Directory.GetCurrentDirectory();
            watcher.Filter              = ServerConstants.ConfigFileName;
            watcher.NotifyFilter        = NotifyFilters.LastWrite;
            watcher.Changed            += this.OnChanged;
            watcher.EnableRaisingEvents = true;
        }
        public void Send(BrokeredMessage requestMessage)
        {
            var topicClient = TopicClient.Create(Topic);

            //send the request message to queue
            topicClient.Send(requestMessage);
        }
Exemplo n.º 8
0
        public PingManager(FileManager fileManager)
        {
            _fileManager = fileManager;
            _client      = TopicClient.Create(TopicName);

            SetupPingOverTime();
            SetupPingNowListener();
        }
Exemplo n.º 9
0
        private void sndTopic_Click(object sender, EventArgs e)
        {
            var             sendingClient = TopicClient.Create("Rugby");
            BrokeredMessage msgBody       = new BrokeredMessage(sendQueueTxt.Text);

            msgBody.Properties.Add("Team", "Munster");

            sendingClient.Send(msgBody);

            status.Text = "Message sent to " + queueNameTxt.Text + " queue.";
        }
        public override void SendMessage(string topicName, BrokeredMessage message)
        {
            if (!_isInitialised)
            {
                Initialise(topicName);
            }

            if (_topicClient == null)
            {
                _topicClient = TopicClient.Create(topicName);
            }
            _topicClient.Send(message);
        }
Exemplo n.º 11
0
        public void SendOrder(Order order)
        {
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("Sending {0} ...", order.Name);

            //create a message from the order
            var orderMsg = new BrokeredMessage(order);

            orderMsg.SetProperties(order.Properties());

            //send the message via SB
            var topicClient = TopicClient.Create(InfrastructureManagement.TopicPath);

            topicClient.Send(orderMsg);

            Console.WriteLine("Done sending {0} !", order.Name);
            Console.ResetColor();
        }
Exemplo n.º 12
0
        private static void SendMessages()
        {
            topicClient = TopicClient.Create(TopicName);

            List <BrokeredMessage> messageList = new List <BrokeredMessage>();

            messageList.Add(CreateSampleMessage("1", "First message information"));
            messageList.Add(CreateSampleMessage("2", "Second message information"));
            messageList.Add(CreateSampleMessage("3", "Third message information"));
            messageList.Add(CreateSampleMessage("4", "Fourth message information"));
            messageList.Add(CreateSampleMessage("5", "Fifth message information"));

            Console.WriteLine("\nSending messages to topic...");


            foreach (BrokeredMessage message in messageList)
            {
                while (true)
                {
                    try
                    {
                        topicClient.Send(message);
                    }
                    catch (MessagingException e)
                    {
                        if (!e.IsTransient)
                        {
                            Console.WriteLine(e.Message);
                            throw;
                        }
                        else
                        {
                            HandleTransientErrors(e);
                        }
                    }
                    Console.WriteLine(string.Format("Message sent: Id = {0}, Body = {1}", message.MessageId, message.GetBody <string>()));
                    break;
                }
            }

            topicClient.Close();
        }
Exemplo n.º 13
0
        private void Send(IEnumerable <Message> messages)
        {
            var         tasks       = new List <Task>();
            TopicClient topicClient = TopicClient.Create(topicName);

            foreach (Message message in messages)
            {
                Logger.Current.Informational("Sending messaage. ");
                var             serializedMessage = JsonConvert.SerializeObject(message);
                BrokeredMessage brokeredMessage   = new BrokeredMessage(serializedMessage);
                brokeredMessage.Properties.Add("LeadScoreConditionType", message.LeadScoreConditionType);
                brokeredMessage.ContentType             = message.GetType().AssemblyQualifiedName;
                brokeredMessage.ScheduledEnqueueTimeUtc = DateTime.UtcNow;
                Task send = topicClient.SendAsync(brokeredMessage).ContinueWith(t =>
                {
                    Logger.Current.Informational("Message sent successfully. ");
                    TrackMessage(message, DateTime.UtcNow);
                });
                tasks.Add(send);
            }
            Task.WaitAll(tasks.ToArray());
        }
Exemplo n.º 14
0
        public TopicClient GetSettingsTopicClient()
        {
            var client = TopicClient.Create(TOPIC_NAME);

            return(client);
        }
Exemplo n.º 15
0
 public MessagePublisher()
 {
     Client = TopicClient.Create(TopicName);
 }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            Console.Title = "Purchases Publisher";
            Console.WriteLine("Verifying existence of Service Bus Topic and Subscriptions");
            // Creating the topic if it does not exist already using the service bus connection string stored in the app.config file
            string connectionString =
                ConfigurationManager.AppSettings["Microsoft.ServiceBus.ConnectionString"];

            var namespaceManager =
                NamespaceManager.CreateFromConnectionString(connectionString);

            // Making sure that the topic exists
            if (!namespaceManager.TopicExists("productsalestopic"))
            {
                namespaceManager.CreateTopic("productsalestopic");
            }

            // Making sure that the subscriptions exists
            if (!namespaceManager.SubscriptionExists("productsalestopic", "AllPurchases"))
            {
                // Create a "Audit" subscription
                namespaceManager.CreateSubscription("productsalestopic",
                                                    "AllPurchases");
            }

            if (!namespaceManager.SubscriptionExists("productsalestopic", "ExpensivePurchases"))
            {
                // Create a "ExpensivePurchases" filtered subscription
                SqlFilter ExpensivePurchasesFilter =
                    new SqlFilter("ProductPrice > 4000");

                namespaceManager.CreateSubscription("productsalestopic",
                                                    "ExpensivePurchases",
                                                    ExpensivePurchasesFilter);
            }

            if (!namespaceManager.SubscriptionExists("productsalestopic", "CheapPurchases"))
            {
                // Create a "CheapPurchases" filtered subscription
                SqlFilter CheapPurchasesFilter =
                    new SqlFilter("ProductPrice <= 4000");

                namespaceManager.CreateSubscription("productsalestopic",
                                                    "CheapPurchases",
                                                    CheapPurchasesFilter);
            }

            Console.WriteLine("Press any key to start publishing messages.");
            Console.ReadKey();

            Console.WriteLine("Sending four messages");
            // Creating four messages for publishing - two with price below 4000$, and two with price above 4000$
            var ShoesMessage = new BrokeredMessage();

            ShoesMessage.Properties["ProductId"]    = 1;
            ShoesMessage.Properties["ProductName"]  = "Shoes";
            ShoesMessage.Properties["ProductPrice"] = 2000;

            var PantsMessage = new BrokeredMessage();

            PantsMessage.Properties["ProductId"]    = 2;
            PantsMessage.Properties["ProductName"]  = "Pants";
            PantsMessage.Properties["ProductPrice"] = 5000;

            var ShirtMessage = new BrokeredMessage();

            ShirtMessage.Properties["ProductId"]    = 3;
            ShirtMessage.Properties["ProductName"]  = "Shirt";
            ShirtMessage.Properties["ProductPrice"] = 3000;

            var JacketMessage = new BrokeredMessage();

            JacketMessage.Properties["ProductId"]    = 4;
            JacketMessage.Properties["ProductName"]  = "Jacket";
            JacketMessage.Properties["ProductPrice"] = 6000;

            TopicClient topicClient = TopicClient.Create("productsalestopic");

            // Sending the messages to service bus
            topicClient.Send(ShoesMessage);
            topicClient.Send(PantsMessage);
            topicClient.Send(ShirtMessage);
            topicClient.Send(JacketMessage);

            Console.WriteLine("Sending complete");
        }
 public FileReadersSettingsManager()
 {
     _client = TopicClient.Create(TopicName);
 }