Exemplo n.º 1
0
        static void Main(string[] args)
        {
            List <Disposable> ThingsToDispose;

            ThingsToDispose = new List <Disposable>();
            const string   Broker       = "tcp://10.197.10.32:61616";
            const string   SubTopicName = "SNP.Inbound";
            TopicPublisher MainPublisher;//publishes to the Pac-Light Outbound topic

            MainPublisher = new TopicPublisher(SubTopicName, Broker);
            ThingsToDispose.Add(new Disposable(nameof(MainPublisher), MainPublisher));
            string rootFolder = @"C:\Users\d.paddock\Desktop\";
            string textFile   = @"Messages.txt";

            string[] lines = null;
            try
            {
                lines = File.ReadAllLines(rootFolder + textFile);
                foreach (string line in lines)
                {
                    MainPublisher.SendMessage(line);
                    Thread.Sleep(100);
                }
            }
            catch
            {
            }
            foreach (Disposable disposable in ThingsToDispose)
            {
                disposable.Dispose();
            }
        }
Exemplo n.º 2
0
        // GET: Publish
        public ActionResult Publish()
        {
            var cfp = new ContextFactoryProperties()
            {
                SolClientLogLevel = SolLogLevel.Warning
            };

            cfp.LogToConsoleError();

            ContextFactory.Instance.Init(cfp);

            try
            {
                // Context must be created first
                using (IContext context = ContextFactory.Instance.CreateContext(new ContextProperties(), null))
                {
                    // Create the application
                    TopicPublisher topicPublisher = new TopicPublisher(_vpnName, _userName, _password);

                    // Run the application within the context and against the host
                    topicPublisher.Run(context, _host);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception thrown: {0}", ex.Message);
            }
            finally
            {
                // Dispose Solace Systems Messaging API
                ContextFactory.Instance.Cleanup();
            }

            return(View());
        }
Exemplo n.º 3
0
        public PublisherClient(string server, string exchange, string routingKey, IConnectionPool connPool, ISerializerNegotiator serializerNegotiator)
        {
            ILoggerProvider loggerProvider = new ConsoleLoggerProvider(new ConsoleLoggerSettings());

            publisher       = new TopicPublisher(server, exchange, connPool, serializerNegotiator, loggerProvider);
            this.routingKey = routingKey;
        }
Exemplo n.º 4
0
        //void m_TransDispatcher_SyncCompleted(object sender, SyncItemEventArgs<TransactionItem> e)
        //{
        //    //TODO:

        //    //e.Item.SyncExpired();
        //}


        public void LoadTopicConfig()
        {
            var config = QueueServerConfig.GetConfig();

            var items = config.RemoteQueueSettings;

            foreach (QueueServerConfigItem item in items)
            {
                //var prop = new QProperties(item.QueueName, item.IsTrans, (CoverMode)item.CoverMode);
                if (item.IsTopic)
                {
                    var publisher = new TopicPublisher()
                    {
                        TopicId   = item.QueueName,
                        TopicName = item.QueueName
                    };

                    string[] strsubs = item.TargetPath.SplitTrim('|');
                    foreach (var s in strsubs)
                    {
                        publisher.AddSubscriber(TopicSubscriber.Create(s, item.QueueName));
                    }

                    var mq = AddQueue(item);
                    QLogger.InfoFormat("Queue Topic Added: {0}", item.Print());
                }
            }
        }
Exemplo n.º 5
0
 public Publisher(string announceIp, int port)
 {
     this.AnnounceIp   = announceIp;
     this.AnnouncePort = port;
     sendSocket        = new UdpSource(announceIp, port);
     writer            = new BatchWriter(sendSocket, 1024 * 128);
     publisher         = new TopicPublisher(writer);
 }
Exemplo n.º 6
0
        public void Save(TopicPublisher publisher)
        {
            string Message = "ý     { \"Machine\":\"" + MachineName + "\",\"Theo\":\"" + Theoretical.ToString() + "\", \"Line\":\"" + Line + "\", \"Engineer\":\"" + Engineer + "\",\"Errors\": \"";

            foreach (string error in NewErrors)
            {
                Message += error + ",";
            }
            Message  = Message.Substring(0, Message.Length - 1);
            Message += "\"}";
            publisher.SendMessage(Message);
        }
Exemplo n.º 7
0
 public void TestPublish()
 {
     using (IMessageSender publisher = new TopicPublisher(BROKER, TOPIC_NAME))
     {
         publisher.Start();
         for (int i = 0; i < 5; i++)
         {
             publisher.SendMessage("This is an unit test #" + (i + 1));
             //Thread.Sleep(1000);
         }
     }
 }
Exemplo n.º 8
0
        //public void AddItem(QueueItem item)
        //{
        //    EventQueue.Enqueue(item);
        //}

        public IQueueAck AddItem(QueueItem item, TopicPublisher Publisher)
        {
            foreach (var subscriber in Publisher.Subscribers.Values)
            {
                var copy = item.Copy();
                copy.Host = subscriber.QHost.RawHostAddress;
                //copy.Args = new NameValueArgs();
                //copy.Args["HostAddress"] = subscriber.Host;
                EventQueue.Enqueue(copy);
            }

            return(new QueueAck(MessageState.Arrived, item));
        }
Exemplo n.º 9
0
        public void Connect()
        {
            ENG_DBDataSource     = ConfigurationManager.AppSettings["ENGDBIP"];
            ENG_DBUserID         = ConfigurationManager.AppSettings["ENGDBUser"];
            ENG_DBPassword       = ConfigurationManager.AppSettings["ENGDBPassword"];
            ENG_DBInitialCatalog = ConfigurationManager.AppSettings["ENGDBDatabase"];
            SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(); //builder to connect to the database

            builder.DataSource     = ENG_DBDataSource;                             //pass it the ip username password and starting database
            builder.UserID         = ENG_DBUserID;
            builder.Password       = ENG_DBPassword;
            builder.InitialCatalog = ENG_DBInitialCatalog;
            ENGDBConnection        = new SqlConnection(builder.ConnectionString);                                                            //turn the string into a connection
            ENGDBConnection.Open();
            Publisher = new TopicPublisher(ConfigurationManager.AppSettings["MainTopicName"], ConfigurationManager.AppSettings["BrokerIP"]); //open the connection
        }
Exemplo n.º 10
0
        public void AddTopic(string QueueName, string TargetPath)
        {
            Publisher = new TopicPublisher()
            {
                TopicId   = QueueName,
                TopicName = QueueName
            };

            string[] strsubs = TargetPath.SplitTrim('|');
            foreach (var s in strsubs)
            {
                AddSubscriber(TopicSubscriber.Create(s, QueueName));
            }
            Logger.Info("Queue Topic Added: {0}", QueueName);
            Initialized = true;
        }
Exemplo n.º 11
0
        private void SendHostConfigQuery()
        {
            PgmSource sendSocket = new PgmSource("224.0.0.23", 7272);

            sendSocket.Start();

            BatchWriter asyncWriter = new BatchWriter(sendSocket, 1024 * 128);

            TopicPublisher publisher = new TopicPublisher(asyncWriter);

            publisher.Start();

            int sendTimeout = 1000;

            publish.PublishObject("Stock-Quotes-AAPL", 123.3, sendTimeout);
        }
Exemplo n.º 12
0
    /// <summary>
    /// CreateEMSServerTopicPublisher creates the Topic we will need to publish to
    /// and binds the Topic to a session and creates the publisher.
    /// </summary>
    private void CreateEMSServerTopicPublisher()
    {
        var topicname = "GeneralTopic";

        Console.WriteLine("Createing a topic we can publish to: " + topicname);

        TopicConnectionFactory factory = new TopicConnectionFactory("localhost");

        publisherConnection = factory.CreateTopicConnection("", ""); // Username, password blank for dev instance
        publisherSession    = publisherConnection.CreateTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        Topic generalTopic = publisherSession.CreateTopic("GeneralTopic");

        emsServerPublisher = publisherSession.CreatePublisher(generalTopic);

        publisherConnection.Start();
    }
Exemplo n.º 13
0
        //public void LoadTopicConfig()
        //{

        //    var config = QueueServerConfig.GetConfig();

        //    var items = config.RemoteQueueSettings;

        //    foreach (QueueServerConfigItem item in items)
        //    {
        //        //var prop = new QProperties(item.QueueName, item.IsTrans, (CoverMode)item.CoverMode);
        //        if (item.IsTopic)
        //        {
        //            var publisher = new TopicPublisher()
        //            {
        //                TopicId = item.QueueName,
        //                TopicName = item.QueueName
        //            };

        //            string[] strsubs = item.TargetPath.SplitTrim('|');
        //            foreach (var s in strsubs)
        //            {
        //                publisher.AddSubscriber(TopicSubscriber.Create(s, item.QueueName));
        //            }

        //            var mq = AddQueue(item);
        //            QLogger.InfoFormat("Queue Topic Added: {0}", item.Print());
        //        }
        //    }
        //}

        public void AddTopic(QueueServerConfigItem item)
        {
            Publisher = new TopicPublisher()
            {
                TopicId   = item.QueueName,
                TopicName = item.QueueName
            };

            string[] strsubs = item.TargetPath.SplitTrim('|');
            foreach (var s in strsubs)
            {
                AddSubscriber(TopicSubscriber.Create(s, item.QueueName));
            }

            //var mq = AddQueue(item);
            Logger.Info("Queue Topic Added: {0}", item.Print());
            Initialized = true;
        }
Exemplo n.º 14
0
        public PgmMulticastingChannel(string address, int port)
        {
            MessageParserFactory = new MessageParserFactory();
            var reader        = new PgmReader(MessageParserFactory);
            var receiveSocket = new PgmReceiver(address, port, reader);

            receiveSocket.Start();


            var sendSocket = new PgmSource(address, port);

            sendSocket.Start();
            var asyncWriter = new BatchWriter(sendSocket, 1500);

            TopicPublisher = new TopicPublisher(asyncWriter);
            TopicPublisher.Start();

            _disposables.Add(receiveSocket);
            _disposables.Add(sendSocket);
        }
Exemplo n.º 15
0
        public UdpMulticastingChannel(string address, int port)
        {
            MessageParserFactory = new MessageParserFactory();
            MessageParser parser        = MessageParserFactory.Create();
            UdpReceiver   receiveSocket = new UdpReceiver(address, port);

            receiveSocket.ReceiveEvent += parser.OnBytes;
            receiveSocket.Start();


            var sendSocket = new UdpSource(address, port);

            sendSocket.Start();
            var asyncWriter = new DaemonWritter(sendSocket);

            //var asyncWriter = new BatchWriter(sendSocket,1500);
            TopicPublisher = new TopicPublisher(asyncWriter);
            TopicPublisher.Start();

            _disposables.Add(receiveSocket);
            _disposables.Add(sendSocket);
        }
Exemplo n.º 16
0
        public void ReadCallback(IAsyncResult ar)
        {
            string content = String.Empty;

            // Retrieve the state object and the handler socket
            // from the asynchronous state object.
            StateObject state   = ar.AsyncState as StateObject;
            Socket      handler = state.workSocket;
            SocketError sckErr;
            // Read data from the client socket.
            int bytesRaed = handler.EndReceive(ar, out sckErr);

            if (sckErr != SocketError.Success)
            {
                return;
            }
            if (bytesRaed > 0)
            {
                // There  might be more data, so store the data received so far.
                state.sb.Append(Encoding.ASCII.GetString(state.buffer, 0, bytesRaed));

                // Check for end-of-file tag. If it is not there, read
                // more data.
                content = state.sb.ToString();

                if (content.IndexOf("true") > -1)
                {
                    string         brokerURL   = "tcp://10.27.68.155:61616";//localhost:61616";
                    string         destination = "BankAlive";
                    IMessageSender publisher   = new TopicPublisher(brokerURL, destination);
                    publisher.Start();
                    publisher.SendMessage <string>("true");
                    // All the data has been read from the
                    // client. Display it on the console.
                    Console.WriteLine("Read {0} bytes from socket. \n Data : {1}",
                                      content.Length, content);

                    // Echo the data back to the client.
                    Send(handler, content);
                }
                else if (content.IndexOf("false") > -1)
                {
                    string         brokerURL   = "tcp://10.27.68.155:61616";//"tcp://localhost:61616";
                    string         destination = "BankAlive";
                    IMessageSender publisher   = new TopicPublisher(brokerURL, destination);
                    publisher.Start();
                    publisher.SendMessage <string>("false");
                    // All the data has been read from the
                    // client. Display it on the console.
                    Console.WriteLine("Read {0} bytes from socket. \n Data : {1}",
                                      content.Length, content);

                    // Echo the data back to the client.
                    Send(handler, content);
                }
                else
                {
                    // Not all data received. Get more.
                    handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, SocketFlags.None, new AsyncCallback(ReadCallback), state);
                }
            }
        }
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            _random     = new Random();
            _startables = new List <IStartable>();
            _publisher  = new TopicPublisher();

            var printerHandler = new PrinterHandler();

            var cashier = new Cashier(_publisher);

            var cashierQueue = CreateQueueThreadHandler(cashier);

            var asstManager = new AssistantManager(_publisher);

            var cookHandlers = CreateCooks();

            var dispatcher           = new BalancedRoundRobin <OrderPlaced>(cookHandlers);
            var cooksDispatcherQueue = new MonitorableQueueThreadHandler <OrderPlaced>(dispatcher);

            _startables.Add(cooksDispatcherQueue);

            var waiter = new Waiter(_publisher);

            var queuesToMonitor = new List <IMonitorableQueue>();

            queuesToMonitor.AddRange(cookHandlers);
            queuesToMonitor.Add(cooksDispatcherQueue);
            var queueMonitor = new QueueMonitor(queuesToMonitor);

            _startables.Add(queueMonitor);

            // Subscriptions
            _publisher.Subscribe(cooksDispatcherQueue);
            _publisher.Subscribe(asstManager);
            _publisher.Subscribe(cashierQueue);
            _publisher.Subscribe(printerHandler);

            _startables.ForEach(x => x.Start());

            bool shutdown      = false;
            int  ordersCreated = 0;

            while (!shutdown)
            {
                if (ordersCreated < 100)
                {
                    PlaceOrders(waiter, 5);
                    ordersCreated += 5;
                }

                var outstandingOrders = cashier.GetOutstandingOrders();

                PrintOutstandingOrders(outstandingOrders);

                foreach (var restaurantDocument in outstandingOrders)
                {
                    cashier.Pay(restaurantDocument.Id);
                }

                var outstandingOrdersAfterPay = cashier.GetOutstandingOrders();
                PrintOutstandingOrders(outstandingOrdersAfterPay);
                PrintDroppedMessages();
                Thread.Sleep(100);
            }
        }
Exemplo n.º 18
0
 public void Delete(TopicPublisher publisher)
 {
     publisher.SendMessage("ü     {\"Machine\": \"" + MachineName + "\", \"Line\":\"" + Line + "\"}");
 }
Exemplo n.º 19
0
 public bool TryAddPublisher(string topicId, TopicPublisher item)
 {
     return(TopicPublishers.TryAdd(topicId, item));
 }
Exemplo n.º 20
0
 public bool TryGetPublisher(string topicId, out TopicPublisher item)
 {
     return(TopicPublishers.TryGetValue(topicId, out item));
 }