예제 #1
0
        public async Task Receive()
        {
            var expected = Guid.NewGuid().ToByteArray();
            var msg      = new Message(expected);

            var rClient = new BusSubscriptionClient(connection, recieveName, subName);

            rClient.OnMessage(this.Get, new MessageHandlerOptions(async(ExceptionReceivedEventArgs args) => { await Task.Run(() => {}); }));

            var sClient = new BusTopicClient(connection, recieveName);
            await sClient.Send(msg);

            for (var i = 0; i < 100 && null == message; i++)
            {
                Thread.Sleep(20);
            }

            if (null == message)
            {
                Assert.Fail("did not recieve message.");
            }
            else
            {
                Assert.AreEqual(expected, message.Body);
            }
        }
예제 #2
0
        public async Task ReceiveBatch()
        {
            var random = new Random();
            var count  = random.Next(1, 11);
            var sent   = new List <Guid>();
            var bq     = new BusTopicClient(name, connection);

            for (var i = 0; i < count; i++)
            {
                var expected = Guid.NewGuid();
                var msg      = new BrokeredMessage(expected);
                await bq.Send(msg);

                sent.Add(expected);
            }

            var r = new BusSubscriptionClient(name, connection, "testing");

            var got = await r.RecieveBatch(count, TimeSpan.FromSeconds(10));

            foreach (var msg in got)
            {
                var result = msg.GetBody <Guid>();
                Assert.IsTrue(sent.Contains(result));
            }
        }
        public void Client()
        {
            var client = new SubscriptionClient(connection, "t", "s");
            var btc    = new BusSubscriptionClient(client);

            Assert.AreEqual(client, btc.Client);
        }
        public void RegisterForEvents()
        {
            var c = new BusSubscriptionClient(new SubscriptionClient(connection, this.topic.Name, "testing"));

            //c.OnMessage((Message msg) => { return Task.Run(() => { }); }, new OnMessageOptions());

            Assert.Fail();
        }
예제 #5
0
        public async Task Receive()
        {
            var expected = Guid.NewGuid();
            var msg      = new BrokeredMessage(expected);
            var bq       = new BusTopicClient(name, connection);
            await bq.Send(msg);

            var r         = new BusSubscriptionClient(name, connection, "testing");
            var resultMsg = await r.Recieve(TimeSpan.FromSeconds(10));

            var result = resultMsg.GetBody <Guid>();

            Assert.AreEqual(expected, result);
        }
예제 #6
0
        public async Task AddRule()
        {
            var random   = new Random();
            var ruleName = string.Format("a{0}b", random.Next());

            var rClient = new BusSubscriptionClient(connection, recieveName, subName);
            await rClient.AddRule(ruleName, new FalseFilter());

            var rules = await rClient.Client.GetRulesAsync();

            var success = false;

            foreach (var r in rules)
            {
                success = r.Name == ruleName;
                if (success)
                {
                    break;
                }
            }
            Assert.IsTrue(success);
        }
예제 #7
0
        public IEnumerable <IRunnable> Tasks(AppConfig config)
        {
            //Setup general queue client (send/recieve)
            var companyClient = new BusQueueClient(config.ConnectionString, config.CompanyQueueName);
            var atClient      = new BusQueueClient(config.ConnectionString, config.AtQueueName);
            var topic         = new BusTopicClient(config.ConnectionString, config.TopicName);
            var employees     = new BusSubscriptionClient(config.ConnectionString, config.TopicName, "all");
            var rademployees  = new BusSubscriptionClient(config.ConnectionString, config.TopicName, "top-earners");

            // Initialize Tasks
            yield return(new InitializeStorageTask(new InitializeQueue(config.ConnectionString, config.CompanyQueueName)));

            yield return(new InitializeStorageTask(new InitializeQueue(config.ConnectionString, config.AtQueueName)));

            yield return(new InitializeStorageTask(new InitializeTopic(config.ConnectionString, config.TopicName)));

            yield return(new InitializeStorageTask(new InitializeSubscription(config.ConnectionString, config.TopicName, employees.Client.SubscriptionName)));

            yield return(new InitializeStorageTask(new InitializeSubscription(config.ConnectionString, config.TopicName, rademployees.Client.SubscriptionName)));

            yield return(new InitializeStorageTask(new InitializeRule(config.ConnectionString, config.TopicName, rademployees.Client.SubscriptionName, "top-earners", new SqlFilter("salary >= 500"))));

            // Compute Tasks
            yield return(new CompanyQueuer(companyClient));

            yield return(new BusEvents <CompanyModel>(companyClient, new CompanyProcessor()));

            yield return(new EmployeeQueuer(topic));

            yield return(new BusEvents <EmployeeModel>(employees, new EmployeeProcessor(false)));

            yield return(new BusEvents <EmployeeModel>(rademployees, new EmployeeProcessor(true)));

            yield return(new AtQueuer(atClient));

            yield return(new BufferedReciever <AtModel>(atClient, new AtProcessor()));
        }
예제 #8
0
        public void RegisterForEvents()
        {
            var c = new BusSubscriptionClient(SubscriptionClient.CreateFromConnectionString(connection, this.topic.Name, "testing"));

            c.OnMessage((BrokeredMessage msg) => { return(Task.Run(() => { })); }, new OnMessageOptions());
        }