Skip to content

How would i send messages to an exchange?  #21

Description

@danammeansbear

I basically want to be able to send messages to the queue or exchange that goes into moving the cubes.

I have the following code written for a c# console app but how would i convert this to your unity code?

  foreach (string greenhouselist in Greenhouse.GreenhouseList)
                {
                    channel.QueueDeclare($"{greenhouselist}Queue",
                durable: true,
                exclusive: false,
                autoDelete: false,
                arguments: null);

                    //channel.ExchangeDeclare("amq.topic", ExchangeType.Fanout);


                    var Count = 0;

                    foreach (string Sensor in Sensor.SensorList)
                    {
                        //var message = new { Name = "Plant Event", Location = greenhouselist, Sensor = Sensor, Saverity = "high", Message = $"Hello! Water me!! Count:{Count}" };
                        //var body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(message));

                        //// string query = "INSERT INTO dbo.greenhouse.message (Name,Price,Date) VALUES('LED Screen','$120','27 January 2017')";
                        ////SqlCommand cmd = new SqlCommand(query, con);
                        //channel.BasicPublish("", $"{greenhouselist}Queue", null, body);
                        foreach (string cube in cube.cubeList)
                        {
                            Random random = new Random();
                            //{ "id":"cube2" "rotY":45 }
                            //{ "id":"cube2", "rotY":45 }
                            //[{ "id":"cube1", "rotX":45 }, { "id":"cube2", "rotY":45 }, { "id":"cube3", "rotZ":45 }]
                            var message1 = @"{ ""id"":""cube2"", ""rotY"":45 }";
                            var message = @"[{ ""id"":""cube2"", ""rotY"":45 }, { ""id"":""cube1"", ""rotX"":90, ""rotY"":23 }, { ""id"":""cube3"", ""rotZ"":29 }]";
                            var message2 = System.Text.RegularExpressions.Regex.Replace(message, "[@\\.;'\\\\]", "");
                            //var message2 = message.Replace(@"\", string.Empty);
                            //var message =  new { id = "Plant Event", rot = greenhouselist, Sensor = Sensor};
                            var body2 = Encoding.UTF8.GetBytes(message2);
                            
                            channel.BasicPublish(exchange: "amq.topic",
                                                 routingKey: "amqpdemo.objects",
                                                 basicProperties: null,
                                                 body: body2);
                     
                            Count++;
                            Thread.Sleep(1000);
                        }
                        Count++;
                        Thread.Sleep(1000);
                    }
       

    }
            }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions