Пример #1
0
 public MessageProducer(Session session, ProducerInfo info)
 {
     _session               = session;
     _info                  = info;
     RequestTimeout         = session.RequestTimeout;
     _messageTransformation = session.Connection.MessageTransformation;
 }
        public async Task CreateProducer(ProducerInfo producerInfo)
        {
            var amqpProducer = new AmqpProducer(this, producerInfo);
            await amqpProducer.Attach();

            producers.TryAdd(producerInfo.Id, amqpProducer);
        }
Пример #3
0
        public override Response ProcessAddProducer(ProducerInfo info)
        {
            if (info != null && info.ProducerId != null)
            {
                SessionId sessionId = info.ProducerId.ParentId;
                if (sessionId != null)
                {
                    ConnectionId connectionId = sessionId.ParentId;
                    if (connectionId != null)
                    {
                        ConnectionState cs;

                        if (connectionStates.TryGetValue(connectionId, out cs))
                        {
                            SessionState ss = cs[sessionId];
                            if (ss != null)
                            {
                                ss.AddProducer(info);
                            }
                        }
                    }
                }
            }
            return(TRACKED_RESPONSE_MARKER);
        }
Пример #4
0
        //
        // Un-marshal an object instance from the data input stream
        //
        public override void TightUnmarshal(OpenWireFormat wireFormat, Object o, BinaryReader dataIn, BooleanStream bs)
        {
            base.TightUnmarshal(wireFormat, o, dataIn, bs);

            ProducerInfo info = (ProducerInfo)o;

            info.ProducerId  = (ProducerId)TightUnmarshalCachedObject(wireFormat, dataIn, bs);
            info.Destination = (ActiveMQDestination)TightUnmarshalCachedObject(wireFormat, dataIn, bs);

            if (bs.ReadBoolean())
            {
                short      size  = dataIn.ReadInt16();
                BrokerId[] value = new BrokerId[size];
                for (int i = 0; i < size; i++)
                {
                    value[i] = (BrokerId)TightUnmarshalNestedObject(wireFormat, dataIn, bs);
                }
                info.BrokerPath = value;
            }
            else
            {
                info.BrokerPath = null;
            }
            info.DispatchAsync = bs.ReadBoolean();
            info.WindowSize    = dataIn.ReadInt32();
        }
 protected void disposeOf(ITransport transport, ProducerInfo producer)
 {
     transport.Oneway(new RemoveInfo()
     {
         ObjectId = producer.ProducerId
     });
 }
        void disposeOf(ProducerInfo producer, ITransport transport)
        {
            RemoveInfo command = new RemoveInfo();

            command.ObjectId = producer.ProducerId;
            transport.Oneway(command);
        }
Пример #7
0
        protected virtual ProducerInfo CreateProducerInfo(IDestination destination)
        {
            ProducerInfo answer = new ProducerInfo();
            ProducerId   id     = new ProducerId();

            id.ConnectionId = info.SessionId.ConnectionId;
            id.SessionId    = info.SessionId.Value;
            lock (this)
            {
                id.Value = ++producerCounter;
            }
            answer.ProducerId  = id;
            answer.Destination = ActiveMQDestination.Transform(destination);

            // If the destination contained a URI query, then use it to set public
            // properties on the ProducerInfo
            ActiveMQDestination amqDestination = destination as ActiveMQDestination;

            if (amqDestination != null && amqDestination.Options != null)
            {
                Util.URISupport.SetProperties(answer, amqDestination.Options, "producer.");
            }

            return(answer);
        }
Пример #8
0
        public MessageProducer(Session session, ProducerId id, ActiveMQDestination destination, TimeSpan requestTimeout)
        {
            this.session        = session;
            this.RequestTimeout = requestTimeout;

            this.info             = new ProducerInfo();
            this.info.ProducerId  = id;
            this.info.Destination = destination;
            this.info.WindowSize  = session.Connection.ProducerWindowSize;

            this.messageTransformation = session.Connection.MessageTransformation;

            // If the destination contained a URI query, then use it to set public
            // properties on the ProducerInfo
            if (destination != null && destination.Options != null)
            {
                URISupport.SetProperties(this.info, destination.Options, "producer.");
            }

            // Version Three and higher will send us a ProducerAck, but only if we
            // have a set producer window size.
            if (session.Connection.ProtocolVersion >= 3 && this.info.WindowSize > 0)
            {
                Tracer.Debug("MessageProducer created with a Window Size of: " + this.info.WindowSize);
                this.usage = new MemoryUsage(this.info.WindowSize);
            }
        }
Пример #9
0
        public async void ProducerPropertiesAccepted(ProducerInfo producer)
        {
            if (producer == null)
            {
                throw new ArgumentNullException(nameof(producer));
            }

            _view.SelectedProducer = await SaveProducerAsync(producer);
        }
        //
        // Write a object instance to data output stream
        //
        public override void LooseMarshal(OpenWireFormat wireFormat, Object o, BinaryWriter dataOut)
        {
            ProducerInfo info = (ProducerInfo)o;

            base.LooseMarshal(wireFormat, o, dataOut);
            LooseMarshalCachedObject(wireFormat, (DataStructure)info.ProducerId, dataOut);
            LooseMarshalCachedObject(wireFormat, (DataStructure)info.Destination, dataOut);
            LooseMarshalObjectArray(wireFormat, info.BrokerPath, dataOut);
        }
        //
        // Write a object instance to data output stream
        //
        public override void TightMarshal2(OpenWireFormat wireFormat, Object o, BinaryWriter dataOut, BooleanStream bs)
        {
            base.TightMarshal2(wireFormat, o, dataOut, bs);

            ProducerInfo info = (ProducerInfo)o;

            TightMarshalCachedObject2(wireFormat, (DataStructure)info.ProducerId, dataOut, bs);
            TightMarshalCachedObject2(wireFormat, (DataStructure)info.Destination, dataOut, bs);
            TightMarshalObjectArray2(wireFormat, info.BrokerPath, dataOut, bs);
        }
Пример #12
0
        public bool Add(ProducerInfo producerInfo)
        {
            if (producerInfo.ProducerId <= 0)
            {
                producerInfo.ProducerId = this.GetMaxId() + 1;
            }
            Parameters cmdParams = GetParameters(producerInfo);

            return(DBHelper.ExecuteProc("PR_Shop_Producer_Add", cmdParams));
        }
Пример #13
0
        public void OpenWireCommandsTest()
        {
            Uri uri = new Uri("failover:(mock://localhost:61616)?transport.randomize=false");
            FailoverTransportFactory factory = new FailoverTransportFactory();

            using (ITransport transport = factory.CreateTransport(uri))
            {
                Assert.IsNotNull(transport);
                transport.Command     = OnCommand;
                transport.Exception   = OnException;
                transport.Resumed     = OnResumed;
                transport.Interrupted = OnInterrupted;

                FailoverTransport failover = transport.Narrow(typeof(FailoverTransport)) as FailoverTransport;
                Assert.IsNotNull(failover);
                Assert.IsFalse(failover.Randomize);

                transport.Start();
                Thread.Sleep(1000);
                Assert.IsTrue(failover.IsConnected);

                ConnectionInfo connection = createConnection();
                transport.Request(connection);
                SessionInfo session1 = createSession(connection);
                transport.Request(session1);
                SessionInfo session2 = createSession(connection);
                transport.Request(session2);
                ConsumerInfo consumer1 = createConsumer(session1);
                transport.Request(consumer1);
                ConsumerInfo consumer2 = createConsumer(session1);
                transport.Request(consumer2);
                ConsumerInfo consumer3 = createConsumer(session2);
                transport.Request(consumer3);

                ProducerInfo producer1 = createProducer(session2);
                transport.Request(producer1);

                // Remove the Producers
                disposeOf(transport, producer1);

                // Remove the Consumers
                disposeOf(transport, consumer1);
                disposeOf(transport, consumer2);
                disposeOf(transport, consumer3);

                // Remove the Session instances.
                disposeOf(transport, session1);
                disposeOf(transport, session2);

                // Indicate that we are done.
                ShutdownInfo shutdown = new ShutdownInfo();
                transport.Oneway(shutdown);
            }
        }
        //
        // Write the booleans that this object uses to a BooleanStream
        //
        public override int TightMarshal1(OpenWireFormat wireFormat, Object o, BooleanStream bs)
        {
            ProducerInfo info = (ProducerInfo)o;

            int rc = base.TightMarshal1(wireFormat, o, bs);

            rc += TightMarshalCachedObject1(wireFormat, (DataStructure)info.ProducerId, bs);
            rc += TightMarshalCachedObject1(wireFormat, (DataStructure)info.Destination, bs);
            rc += TightMarshalObjectArray1(wireFormat, info.BrokerPath, bs);

            return(rc + 0);
        }
Пример #15
0
        public MessageProducer(Session session, ProducerInfo info)
        {
            this.session        = session;
            this.info           = info;
            this.RequestTimeout = session.RequestTimeout;

            // Version Three and higher will send us a ProducerAck, but only if we
            // have a set producer window size.
            if (session.Connection.ProtocolVersion >= 3 && info.WindowSize > 0)
            {
                usage = new MemoryUsage(info.WindowSize);
            }
        }
Пример #16
0
        private ProducerInfo CreateProducerInfo(int value)
        {
            ProducerId pid = new ProducerId();

            pid.Value        = value;
            pid.ConnectionId = "CONNECTION";
            pid.SessionId    = 1;
            ProducerInfo info = new ProducerInfo();

            info.ProducerId = pid;

            return(info);
        }
        ProducerInfo createProducer(SessionInfo parent)
        {
            ProducerId id = new ProducerId();

            id.ConnectionId = parent.SessionId.ConnectionId;
            id.SessionId    = parent.SessionId.Value;
            id.Value        = producerIdx++;

            ProducerInfo info = new ProducerInfo();

            info.ProducerId = id;

            return(info);
        }
Пример #18
0
        public void AddProducer(ProducerInfo info)
        {
            CheckShutdown();
            ProducerState producerState = new ProducerState(info);

            if (producers.ContainsKey(info.ProducerId))
            {
                producers[info.ProducerId] = producerState;
            }
            else
            {
                producers.Add(info.ProducerId, producerState);
            }
        }
Пример #19
0
        public ActionResult ProducerDetails(int id)
        {
            if (!isAdmin())
            {
                return(RedirectToAction("LogIn", "Main"));
            }
            Producer prodDetails = _categoryBLL.producerDetails(id);

            ProducerInfo prodinfo = new ProducerInfo()
            {
                prodId   = prodDetails.id,
                prodName = prodDetails.name
            };

            return(View(prodinfo));
        }
Пример #20
0
        public ProducerDialog(ProducerInfo producer)
        {
            if (producer == null)
            {
                throw new ArgumentNullException(nameof(producer));
            }

            InitializeComponent();

            _id = producer.Id;
            bindingSource.DataSource = producer;
            nameTextBox.RequireValue(errorProvider);
            addressTextBox.RequireValue(errorProvider);

            nameTextBox.TextChanged    += (sender, args) => EnableOperations();
            addressTextBox.TextChanged += (sender, args) => EnableOperations();
            EnableOperations();
        }
Пример #21
0
 public void RegisterProducer(ITcpConnection connection, string producerId)
 {
     var connectionId = connection.RemotingEndPoint.ToAddress();
     _producerInfoDict.AddOrUpdate(connectionId, key =>
     {
         var producerInfo = new ProducerInfo
         {
             ProducerId = producerId,
             HeartbeatInfo = new ClientHeartbeatInfo(connection) { LastHeartbeatTime = DateTime.Now }
         };
         _logger.InfoFormat("Producer registered, producerId: {0}, connectionId: {1}", producerId, key);
         return producerInfo;
     }, (key, existingProducerInfo) =>
     {
         existingProducerInfo.HeartbeatInfo.LastHeartbeatTime = DateTime.Now;
         return existingProducerInfo;
     });
 }
        private static async Task SendAsync(ProducerInfo producerInfo)
        {
            List <ProducerResult> producerResults = new List <ProducerResult>();
            string topicName = producerInfo.TopicName; //Environment.GetEnvironmentVariable("TOPIC_NAME");
            string port      = producerInfo.Port.ToString();
            string address   = producerInfo.Address;
            var    kafkaUrl  = address + "/" + port; //Environment.GetEnvironmentVariable("KAFKA_URL");

            var config = new ProducerConfig
            {
                BootstrapServers = kafkaUrl
            };

            // Create a producer that can be used to send messages to kafka that have no key and a value of type string
            using var p = new ProducerBuilder <object, object>(config).Build();

            var i = 0;

            while (true)
            {
                // Construct the message to send (generic type must match what was used above when creating the producer)
                var message = new Message <object, object>
                {
                    Value = $"Message #{++i}"
                };

                // Send the message to our test topic in Kafka
                var dr = await p.ProduceAsync(topicName, message);

                Console.WriteLine($"Produced message '{dr.Value}' to topic {dr.Topic}, partition {dr.Partition}, offset {dr.Offset}");

                results.Add(new ProducerResult
                {
                    Message       = dr.Value,
                    Topic         = dr.Topic,
                    Partition     = dr.Partition,
                    Offset        = dr.Offset,
                    ProduceStatus = "Produced"
                });

                Thread.Sleep(TimeSpan.FromMilliseconds(5000));
            }
        }
Пример #23
0
 private ProducerResponseDTO ProducerInfo(ProducerInfo producer)
 {
     if (producer != null)
     {
         return(new ProducerResponseDTO()
         {
             ProducerId = producer.ProducerId,
             Bio = producer.Bio,
             CreatedDate = producer.CreatedDate,
             DOB = producer.DOB,
             ModifiedDate = producer.ModifiedDate,
             Name = producer.Name,
             ProducedMovies = this.MoviesByProducer(producer.MovieInfoes.ToList()),
             Sex = producer.Sex,
             Status = producer.Status
         });
     }
     return(new ProducerResponseDTO());
 }
Пример #24
0
        protected virtual ProducerInfo CreateProducerInfo(IDestination destination)
        {
            ProducerInfo answer = new ProducerInfo();

            answer.ProducerId  = GetNextProducerId();
            answer.Destination = Destination.Transform(destination);

            // If the destination contained a URI query, then use it to set public
            // properties on the ProducerInfo
            Destination amqDestination = destination as Destination;

            if (amqDestination != null && amqDestination.Options != null)
            {
                StringDictionary options = URISupport.GetProperties(amqDestination.Options, "producer.");
                URISupport.SetProperties(answer, options);
            }

            return(answer);
        }
Пример #25
0
        private static Parameters GetParameters(ProducerInfo producerInfo)
        {
            Parameters parameters = new Parameters();

            parameters.AddInParameter("@ProducerID", DbType.Int32, producerInfo.ProducerId);
            parameters.AddInParameter("@ProducerName", DbType.String, producerInfo.ProducerName);
            parameters.AddInParameter("@ProducerShortName", DbType.String, producerInfo.ProducerShortName);
            parameters.AddInParameter("@Birthday", DbType.DateTime, producerInfo.BirthDay);
            parameters.AddInParameter("@Address", DbType.String, producerInfo.Address);
            parameters.AddInParameter("@Phone", DbType.String, producerInfo.Phone);
            parameters.AddInParameter("@Fax", DbType.String, producerInfo.Fax);
            parameters.AddInParameter("@Postcode", DbType.String, producerInfo.Postcode);
            parameters.AddInParameter("@Homepage", DbType.String, producerInfo.Homepage);
            parameters.AddInParameter("@Email", DbType.String, producerInfo.Email);
            parameters.AddInParameter("@ProducerIntro", DbType.String, producerInfo.ProducerIntro);
            parameters.AddInParameter("@ProducerPhoto", DbType.String, producerInfo.ProducerPhoto);
            parameters.AddInParameter("@ProducerType", DbType.Int32, producerInfo.ProducerType);
            return(parameters);
        }
Пример #26
0
        private async Task <ProducerInfo> SaveProducerAsync(ProducerInfo producer)
        {
            if (_view.Producers.All(x => x.Id != producer.Id))
            {
                producer = await _producerService.AddAsync(producer);

                _view.Producers.Add(producer);
            }
            else
            {
                await _producerService.UpdateAsync(producer);

                producer = await _producerService.GetAsync(producer.Id);

                _view.Producers.AddOrReplace(x => x.Id == producer.Id, producer);
            }

            return(producer);
        }
Пример #27
0
        private static void SendMessage(object param)
        {
            string producerName = Thread.CurrentThread.Name;

            Console.WriteLine("{0} Running...", producerName);

            IChannelFactory <IService> channelFatory = new ChannelFactory <IService>(netTcpBinding, remoteAddress);
            IService consumer = channelFatory.CreateChannel(remoteAddress);

            ProducerInfo producer = new ProducerInfo((Int16)param, producerName);

            for (Int64 i = 0; i < Settings.Messaging.MessagePerProducer; i++)
            {
                Payload payload = new Payload(producer, i, String.Format("Hello World from {0}", producerName));
                Byte[]  bytes   = BinarySerializer.Serialize <Payload>(payload);
                consumer.Process(bytes);
            }

            channelFatory.Close();
        }
Пример #28
0
        public ActionResult ProducerDetails(int id, ProducerInfo pi)
        {
            if (!isAdmin())
            {
                return(RedirectToAction("LogIn", "Main"));
            }

            if (ModelState.IsValid)
            {
                Customer c = (Customer)Session["loggedInUser"];
                Producer p = new Producer();
                p.name = pi.prodName;
                var result = _categoryBLL.updateProducer(id, p, c.id);
                if (result)
                {
                    return(Json(new { success = true, message = p.name + " ble endret.", redirect = "/Category/ListProducers/" }));
                }
                return(Json(new { success = false, message = "noe gikk galt, prøv igjen senere." }));
            }
            return(Json(new { success = false, message = "Feil i validering" }));
        }
Пример #29
0
        public ActionResult addProducer(ProducerInfo producerinfo)
        {
            if (!isAdmin())
            {
                return(RedirectToAction("LogIn", "Main"));
            }

            if (ModelState.IsValid)
            {
                Customer c    = (Customer)Session["loggedInUser"];
                Producer prod = new Producer();
                prod.id   = producerinfo.prodId;
                prod.name = producerinfo.prodName;
                bool OK = _categoryBLL.AddProducer(prod, c.id);
                if (OK)
                {
                    return(Json(new { success = true, message = prod.name + " ble lagt til.", redirect = "/Category/ListProducers?item_desc" }));
                }
                return(Json(new { success = false, message = "noe gikk galt, prøv igjen senere." }));
            }
            return(Json(new { success = false, message = "Feil i validering" }));
        }
Пример #30
0
        private static ProducerInfo producerInfoFromrdataReader(NullableDataReader dataReader)
        {
            ProducerInfo info = new ProducerInfo();

            info.ProducerId        = dataReader.GetInt32("ProducerID");
            info.ProducerName      = dataReader.GetString("ProducerName");
            info.ProducerShortName = dataReader.GetString("ProducerShortName");
            info.BirthDay          = dataReader.GetNullableDateTime("BirthDay");
            info.Address           = dataReader.GetString("Address");
            info.Phone             = dataReader.GetString("Phone");
            info.Fax           = dataReader.GetString("Fax");
            info.Postcode      = dataReader.GetString("Postcode");
            info.Homepage      = dataReader.GetString("Homepage");
            info.Email         = dataReader.GetString("Email");
            info.ProducerIntro = dataReader.GetString("ProducerIntro");
            info.ProducerPhoto = dataReader.GetString("ProducerPhoto");
            info.ProducerType  = dataReader.GetInt32("ProducerType");
            info.Passed        = dataReader.GetBoolean("Passed");
            info.OnTop         = dataReader.GetBoolean("OnTop");
            info.IsElite       = dataReader.GetBoolean("IsElite");
            return(info);
        }
Пример #31
0
        public void RegisterProducer(ITcpConnection connection, string producerId)
        {
            var connectionId = connection.RemotingEndPoint.ToAddress();

            _producerInfoDict.AddOrUpdate(connectionId, key =>
            {
                var producerInfo = new ProducerInfo
                {
                    ProducerId    = producerId,
                    HeartbeatInfo = new ClientHeartbeatInfo(connection)
                    {
                        LastHeartbeatTime = DateTime.Now
                    }
                };
                _logger.InfoFormat("Producer registered, producerId: {0}, connectionId: {1}", producerId, key);
                return(producerInfo);
            }, (key, existingProducerInfo) =>
            {
                existingProducerInfo.HeartbeatInfo.LastHeartbeatTime = DateTime.Now;
                return(existingProducerInfo);
            });
        }