Example #1
0
        public static void SendAMQPMessage(string payload)
        {
            string eventHubNamespace = "kioskeventhub";
            string eventHubName      = "hub1";
            string policyName        = "AllowSend";
            string key          = "tvzonqLkFUm+9AXlT/rq8Fmh0HlzND7MwOiGW6r0TNo=";
            string partitionkey = "partitionkey";

            //Endpoint = sb://kioskeventhub.servicebus.windows.net/;SharedAccessKeyName=SendPolicy;SharedAccessKey=/ncGKkouu7a4qVdEHPgwdmBv5p2fGDGf7aPHjD0/5n8=;EntityPath=hub1

            string data = payload;

            Amqp.Address address = new Amqp.Address(
                string.Format("{0}.servicebus.windows.net", eventHubNamespace),
                5671, policyName, key);

            Amqp.Connection connection = new Amqp.Connection(address);
            Amqp.Session    session    = new Amqp.Session(connection);
            Amqp.SenderLink senderlink = new Amqp.SenderLink(session,
                                                             string.Format("send-link:{0}", eventHubName), eventHubName);

            Amqp.Message message = new Amqp.Message()
            {
                BodySection = new Amqp.Framing.Data()
                {
                    Binary = System.Text.Encoding.UTF8.GetBytes(data)
                }
            };

            message.MessageAnnotations = new Amqp.Framing.MessageAnnotations();
            message.MessageAnnotations[new Amqp.Types.Symbol("x-opt-partition-key")] =
                string.Format("pk:", partitionkey);

            senderlink.Send(message);
        }
Example #2
0
//        const string amqpAddress="amqps://*****:*****@egms-sensorhub-ns.servicebus.windows.net"
        private void TestEventHub()
        {
            string amqpAddress = "amqps://" + policyName + ":" + EGIoTKit.Utility.HttpUtility.UrlEncode(accessKey) + "@" + ehNSName + ".servicebus.windows.net";
            var    address     = new Amqp.Address(amqpAddress);
            var    connection  = new Amqp.Connection(address);
            var    session     = new Amqp.Session(connection);
            var    amqpSender  = new Amqp.SenderLink(session, "send-link" + ehName, ehName + "/Patritions/1");
            var    message     = new Amqp.Message(System.Text.UTF8Encoding.UTF8.GetBytes("Hello EG Iot Kit Emulator"));

            amqpSender.Send(message);
        }
Example #3
0
        private async Task sendMessage(string data, int count)
        {
            if (SendEnabled)
            {
                if (eventHubs)
                {
                    var    config            = Config.Default;
                    string eventHubNamespace = config.EventHubNamespace;
                    string eventHubName      = config.EventHubName;
                    string policyName        = config.PolicyName;
                    string key          = config.Key;
                    string partitionkey = config.Partitionkey;

                    Amqp.Address address = new Amqp.Address(
                        string.Format("{0}.servicebus.windows.net", eventHubNamespace),
                        5671, policyName, key);

                    Amqp.Connection connection = new Amqp.Connection(address);
                    Amqp.Session    session    = new Amqp.Session(connection);
                    Amqp.SenderLink senderlink = new Amqp.SenderLink(session,
                                                                     string.Format("send-link:{0}", eventHubName), eventHubName);

                    Amqp.Message message = new Amqp.Message()
                    {
                        BodySection = new Amqp.Framing.Data()
                        {
                            Binary = System.Text.Encoding.UTF8.GetBytes(data)
                        }
                    };

                    message.MessageAnnotations = new Amqp.Framing.MessageAnnotations();
                    message.MessageAnnotations[new Amqp.Types.Symbol("x-opt-partition-key")] =
                        string.Format("pk:", partitionkey);
                    await Task.Run(() => senderlink.Send(message));
                }
                else
                {
                    var message = new Message(Encoding.UTF8.GetBytes(data));
                    await deviceClient.SendEventAsync(message);
                }
                Logger.LogInfo($"Sent {count} values as a single message");
                incrementSends();
            }
        }
        private Task <Amqp.Connection> CreateSecureConnection(Amqp.Address addr, Amqp.Framing.Open open, Amqp.OnOpened onOpened)
        {
            ProviderCreateConnection delagate = base.CreateConnectionBuilder();

            return(delagate.Invoke(addr, open, onOpened));
        }