public ONSOrderProducer(string topic, string producerId, OrderProducer orderProducer)
 {
     this.Topic      = topic;
     this.ProducerId = producerId;
     this.Type       = ONSMessageType.ORDER.ToString().ToUpper();
     _producer       = orderProducer;
 }
Example #2
0
        static void Main(string[] args)
        {
            ONSFactoryProperty factoryInfo = new ONSFactoryProperty();

            factoryInfo.setFactoryProperty(factoryInfo.getProducerIdName(), "PID_1234");
            Console.WriteLine("ProducerId:{0}, \nConsumerId:{1},\nPublishTopics:{2},\nMsgContent:{3},\nAccessKey::{4},\nSecretKey::{5} ",
                              factoryInfo.getProducerId(), factoryInfo.getConsumerId(), factoryInfo.getPublishTopics(),
                              factoryInfo.getMessageContent(), factoryInfo.getAccessKey(), factoryInfo.getSecretKey());

            ONSFactory onsfactory = new ONSFactory();

            OrderProducer pProducer = onsfactory.getInstance().createOrderProducer(factoryInfo);

            pProducer.start();

            string key = "abc";

            for (int i = 0; i < 20; ++i)
            {
                Message msg = new Message("Ram_Topic_2", "TagA", "msg from for loop => " + i);
                try
                {
                    SendResultONS sendResult = pProducer.send(msg, key);
                    Console.WriteLine("=> send success : {0} ", sendResult.getMessageId());
                }
                catch (ONSClientException e)
                {
                    Console.WriteLine("\nexception of sendmsg:{0}", e.what());
                }
            }

            Thread.Sleep(1000 * 100);
            pProducer.shutdown();
        }
Example #3
0
 /// <summary>
 ///     开启生产消息
 /// </summary>
 public void Start()
 {
     if (_producer == null)
     {
         // 获取实产者实例
         _producer = ONSFactory.getInstance().createOrderProducer(_factoryInfo);
         _producer.start();
     }
 }
Example #4
0
        protected override IONSProducer InitilizeProducer(ONSFactoryProperty onsProducerFactoryProperty)
        {
            //实例化OrderProducer
            OrderProducer orderProducer = ONSFactory.getInstance().createOrderProducer(onsProducerFactoryProperty);
            //实例化代理类ONSOrderProducer
            IONSProducer producer = new ONSOrderProducer(this.Topic, this.Pid, orderProducer);

            return(producer);
        }
Example #5
0
        static void Main(string[] args)
        {
            SyncEvents syncEvents = new SyncEvents();
            Queue<Order> queue = new Queue<Order>();

            Console.WriteLine("Configuring worker threads...");

            orderProducer = new OrderProducer(queue, syncEvents);
            orderConsumer = new OrderConsumer(queue, syncEvents);

            Thread consumerThread = new Thread(orderConsumer.ThreadRun);
            Console.WriteLine("Launching consumer threads...");
            consumerThread.Start();

            Console.WriteLine("USAGE: \n\tusername: enqueue order \n\t[username],[username]: enqueue multi order \n\t/show: display current queue \n\t/stop: close queue service \n\t/quit: exit this program");

            string input;
            while (!string.Equals((input = Console.ReadLine()), "/quit", StringComparison.OrdinalIgnoreCase))
            {
                if (string.IsNullOrEmpty(input))
                {
                    Console.WriteLine("please input command");
                }
                else
                {
                    bool isBreak=false;
                    switch (input.ToLower())
                    {
                        case "/stop":
                            Console.WriteLine("Signaling threads to terminate...");
                            syncEvents.ExitThreadEvent.Set();
                            Console.WriteLine("main thread waiting for threads to finish...");
                            consumerThread.Join();
                            Console.WriteLine("service stoped");
                            isBreak = true;
                            break;
                        case "/show":
                            ShowQueueContents(queue);
                            break;
                        default:
                            foreach (var username in input.Split(','))
                            {
                                orderProducer.EnqueueOrder(new Order() { CreateDate = DateTime.Now, UserName = username });
                            }
                            break;
                    }
                    if (isBreak)
                    {
                        Console.ReadKey();
                        break;
                    }
                }
            }

            syncEvents.ExitThreadEvent.Set();
        }
Example #6
0
        public virtual OrderProducer createOrderProducer(ONSFactoryProperty factoryProperty)
        {
            global::System.IntPtr cPtr = ONSClient4CPPPINVOKE.ONSFactoryAPI_createOrderProducer(swigCPtr, ONSFactoryProperty.getCPtr(factoryProperty));
            OrderProducer         ret  = (cPtr == global::System.IntPtr.Zero) ? null : new OrderProducer(cPtr, false);

            if (ONSClient4CPPPINVOKE.SWIGPendingException.Pending)
            {
                throw ONSClient4CPPPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Example #7
0
 public static void CreateOrderProducer()
 {
     _orderproducer = ONSFactory.getInstance().createOrderProducer(getFactoryProperty());
 }
Example #8
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(OrderProducer obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
Example #9
0
 public void InitializeOrderProducer()
 {
     orderProducer = ONSFactory.getInstance().createOrderProducer(factoryInfo);
     orderProducer.start();
 }
Example #10
0
 /// <summary>
 ///     关闭生产者
 /// </summary>
 public void Close()
 {
     _producer?.shutdown();
     _producer = null;
 }
Example #11
0
 public override void Start()
 {
     producer = ONSFactory.getInstance().createOrderProducer(this.FactoryProperty);
     producer.start();
 }