public async void PublishBinaryMessages()
    {
        string randomName     = _pubsubFixture.RandomName();
        string topicId        = $"testTopicForProtoBinaryMessageCreation{randomName}";
        string subscriptionId = $"testSubscriptionForProtoBinaryMessageCreation{randomName}";
        string schemaId       = $"testSchemaForProtoBinaryMessageCreation{randomName}";

        var schema = _pubsubFixture.CreateProtoSchema(schemaId);

        _pubsubFixture.CreateTopicWithSchema(topicId, schema.Name.ToString(), Encoding.Binary);
        _pubsubFixture.CreateSubscription(topicId, subscriptionId);

        List <Utilities.State> messageTexts = new List <Utilities.State> {
            new Utilities.State {
                Name = "New York", PostAbbr = "NY"
            }, new Utilities.State {
                Name = "Pennsylvania", PostAbbr = "PA"
            }
        };

        var output = await _publishProtoMessagesAsyncSample.PublishProtoMessagesAsync(_pubsubFixture.ProjectId, topicId, messageTexts);

        Assert.Equal(messageTexts.Count, output);

        // Pull the Message to confirm it is valid
        var result = await _pullMessagesAsyncSample.PullMessagesAsync(_pubsubFixture.ProjectId, subscriptionId, false);

        Assert.True(result > 0);
    }
Пример #2
0
    public async void PullProtoBinaryMessagesAsync()
    {
        string randomName     = _pubsubFixture.RandomName();
        string topicId        = $"testTopicForProtoBinaryMessageAck{randomName}";
        string subscriptionId = $"testSubscriptionForProtoBinaryMessageAck{randomName}";
        string schemaId       = $"testSchemaForProtoBinaryMessageAck{randomName}";

        var schema = _pubsubFixture.CreateProtoSchema(schemaId);

        _pubsubFixture.CreateTopicWithSchema(topicId, schema.Name.ToString(), Encoding.Binary);
        _pubsubFixture.CreateSubscription(topicId, subscriptionId);

        await _publishProtoMessagesAsyncSample.PublishProtoMessagesAsync(_pubsubFixture.ProjectId, topicId, new Utilities.State[] { new Utilities.State {
                                                                                                                                        Name = "New York", PostAbbr = "NY"
                                                                                                                                    } });

        // Pull and acknowledge the messages
        var result = await _pullProtoMessagesAsyncSample.PullProtoMessagesAsync(_pubsubFixture.ProjectId, subscriptionId, true);

        Assert.Equal(1, result);

        //Pull the Message to confirm it's gone after it's acknowledged
        result = await _pullProtoMessagesAsyncSample.PullProtoMessagesAsync(_pubsubFixture.ProjectId, subscriptionId, true);

        Assert.True(result == 0);
    }
Пример #3
0
    public async void PullAvroBinaryMessagesAsync()
    {
        string randomName     = _pubsubFixture.RandomName();
        string topicId        = $"testTopicForAvroBinaryMessageAck{randomName}";
        string subscriptionId = $"testSubscriptionForAvroBinaryMessageAck{randomName}";
        string schemaId       = $"testSchemaForAvroMessageBinaryAck{randomName}";

        var schema = _pubsubFixture.CreateAvroSchema(schemaId);

        _pubsubFixture.CreateTopicWithSchema(topicId, schema.Name.ToString(), Encoding.Binary);
        _pubsubFixture.CreateSubscription(topicId, subscriptionId);

        await _publishAvroMessagesAsyncSample.PublishAvroMessagesAsync(_pubsubFixture.ProjectId, topicId, new AvroUtilities.State[] { new AvroUtilities.State {
                                                                                                                                          name = "New York", post_abbr = "NY"
                                                                                                                                      } });

        await _pubsubFixture.Pull.Eventually(async() =>
        {
            // Pull and acknowledge the messages
            var result = await _pullAvroMessagesAsyncSample.PullAvroMessagesAsync(_pubsubFixture.ProjectId, subscriptionId, true);
            Assert.Equal(1, result);
        });

        //Pull the Message to confirm it's gone after it's acknowledged
        var result = await _pullAvroMessagesAsyncSample.PullAvroMessagesAsync(_pubsubFixture.ProjectId, subscriptionId, true);

        Assert.Equal(0, result);
    }
Пример #4
0
    public async Task PublishBinaryMessages()
    {
        string randomName     = _pubsubFixture.RandomName();
        string topicId        = $"testTopicAvroBinaryMessageCreation{randomName}";
        string subscriptionId = $"testSubscriptionAvroBinaryMessageCreation{randomName}";
        string schemaId       = $"testSchemaAvroBinaryMessageCreation{randomName}";

        var schema = _pubsubFixture.CreateAvroSchema(schemaId);

        _pubsubFixture.CreateTopicWithSchema(topicId, schema.Name.ToString(), Encoding.Binary);
        _pubsubFixture.CreateSubscription(topicId, subscriptionId);

        List <AvroUtilities.State> messageTexts = new List <AvroUtilities.State> {
            new AvroUtilities.State {
                name = "New York", post_abbr = "NY"
            }, new AvroUtilities.State {
                name = "Pennsylvania", post_abbr = "PA"
            }
        };

        var output = await _publishAvroMessagesAsyncSample.PublishAvroMessagesAsync(_pubsubFixture.ProjectId, topicId, messageTexts);

        Assert.Equal(messageTexts.Count, output);

        // Pull the Message to confirm it is valid
        await _pubsubFixture.Pull.Eventually(async() =>
        {
            var result = await _pullMessagesAsyncSample.PullMessagesAsync(_pubsubFixture.ProjectId, subscriptionId, false);
            Assert.True(result > 0);
        });
    }
Пример #5
0
    public async Task PullMessagesWithFlowControlAsync()
    {
        string topicId = $"testTopicForMessageWithFlowControlAck{_pubsubFixture.RandomName()}";

        _pubsubFixture.CreateTopic(topicId);

        // For this sample in particular, we need to retry the sbscription creation, the message publishing etc.
        // That's because this sample is configuring the ack deadline of the subscriber, which will be extended
        // automatically. While Pub/Sub has sent a message to a subscriber it will avoid sending it to another subscriber
        // of the same subscription until the ack deadline has expired. Since we are renewing the ack deadline, it won't
        // expire (soon) and if the message is sent but not acked, then Pub/Sub won't attempt to send the message
        // to a different susbcriber even if we keep retrying, as it is waiting for the ack deadline to expire, which we
        // keep extending.
        await _pubsubFixture.Pull.Eventually(async() =>
        {
            string subscriptionId = $"testSubscriptionForMessageWithFlowControlAck{_pubsubFixture.RandomName()}";
            _pubsubFixture.CreateSubscription(topicId, subscriptionId);

            var message = _pubsubFixture.RandomName();
            await _publishMessagesAsyncSample.PublishMessagesAsync(_pubsubFixture.ProjectId, topicId, new string[] { message });

            // Pull and acknowledge the messages
            var result = await _pullMessagesCustomAsyncSample.PullMessagesWithFlowControlAsync(_pubsubFixture.ProjectId, subscriptionId, true);
            Assert.Equal(1, result);

            //Pull the Message to confirm it's gone after it's acknowledged
            result = await _pullMessagesCustomAsyncSample.PullMessagesWithFlowControlAsync(_pubsubFixture.ProjectId, subscriptionId, true);
            Assert.Equal(0, result);
        });
    }
Пример #6
0
    public void GetSubscriptionPolicy()
    {
        string topicId        = "testTopicGetSubscriptionIamPolicy" + _pubsubFixture.RandomName();
        string subscriptionId = "testSubscriptionGetSubscriptionIamPolicy";

        _pubsubFixture.CreateTopic(topicId);
        _pubsubFixture.CreateSubscription(topicId, subscriptionId);

        var policy = _getSubscriptionIamPolicySample.GetSubscriptionIamPolicy(_pubsubFixture.ProjectId, subscriptionId);

        Assert.NotNull(policy);
    }
Пример #7
0
    public void TestListSubscriptions()
    {
        string topicId        = "testTopicForListingSubscriptions" + _pubsubFixture.RandomName();
        string subscriptionId = "testSubscriptionForListingSubscriptions" + _pubsubFixture.RandomName();

        _pubsubFixture.CreateTopic(topicId);
        _pubsubFixture.CreateSubscription(topicId, subscriptionId);

        var subscriptions = _listSubscriptionsSample.ListSubscriptions(_pubsubFixture.ProjectId);

        Assert.Contains(subscriptions.Select(s => s.SubscriptionName.SubscriptionId), c => c.Contains(subscriptionId));
    }
Пример #8
0
    public void TestDeleteSubscription()
    {
        string topicId        = "testTopicForDeleteSubscription" + _pubsubFixture.RandomName();
        string subscriptionId = "testSubscriptionForDeleteSubscription" + _pubsubFixture.RandomName();

        _pubsubFixture.CreateTopic(topicId);
        _pubsubFixture.CreateSubscription(topicId, subscriptionId);

        _deleteSubscriptionSample.DeleteSubscription(_pubsubFixture.ProjectId, subscriptionId);

        Exception e = Assert.Throws <Grpc.Core.RpcException>(() => _pubsubFixture.GetSubscription(subscriptionId));

        _pubsubFixture.TempSubscriptionIds.Remove(subscriptionId);  // We already deleted it.
    }
    public void SetSubscriptionIamPolicy()
    {
        string topicId                  = "testTopicSetSubscriptionIamPolicy" + _pubsubFixture.RandomName();
        string subscriptionId           = "testSubscriptionSetSubscriptionIamPolicy" + _pubsubFixture.RandomName();
        string testRoleValueToConfirm   = "pubsub.editor";
        string testMemberValueToConfirm = "group:[email protected]";

        _pubsubFixture.CreateTopic(topicId);
        _pubsubFixture.CreateSubscription(topicId, subscriptionId);

        var policy = _setSubscriptionIamPolicySample.SetSubscriptionIamPolicy(_pubsubFixture.ProjectId, subscriptionId, testRoleValueToConfirm, testMemberValueToConfirm);

        Assert.Equal($"roles/{testRoleValueToConfirm}", policy.Bindings[0].Role);
        Assert.Contains(policy.Bindings[0].Members, c => c.Contains(testMemberValueToConfirm));
    }
Пример #10
0
    public void TestListSubscriptionsInTopic()
    {
        string randomName     = _pubsubFixture.RandomName();
        string topicId        = $"testTopicForListSubscriptionsInTopic{randomName}";
        string subscriptionId = $"testSubscriptionForListSubscriptionsInTopic{randomName}";

        _pubsubFixture.CreateTopic(topicId);
        _pubsubFixture.CreateSubscription(topicId, subscriptionId);

        var subscriptions = _listSubscriptionsInTopicSample.ListSubscriptionsInTopic(_pubsubFixture.ProjectId, topicId).ToList();

        SubscriptionName subscriptionName = SubscriptionName.FromProjectSubscription(_pubsubFixture.ProjectId, subscriptionId);

        Assert.Contains(subscriptions, s => s == subscriptionName.ToString());
    }
Пример #11
0
    public void TestDetachSubscription()
    {
        string randomName     = _pubsubFixture.RandomName();
        string topicId        = $"testTopicForDetachSubscription{randomName}";
        string subscriptionId = $"testSubscriptionForDetachSubscription{randomName}";

        _pubsubFixture.CreateTopic(topicId);
        _pubsubFixture.CreateSubscription(topicId, subscriptionId);

        _detachSubscriptionSample.DetachSubscription(_pubsubFixture.ProjectId, subscriptionId);

        var subscription = _pubsubFixture.GetSubscription(subscriptionId);

        Assert.True(subscription.Detached);
    }
    public void SubscriptionPolicyPermisssions()
    {
        string topicId                  = "testTopicForTestSubscriptionIamPolicy" + _pubsubFixture.RandomName();
        string subscriptionId           = "testSubscriptionForTestSubscriptionIamPolicy" + _pubsubFixture.RandomName();
        string testRoleValueToConfirm   = "pubsub.editor";
        string testMemberValueToConfirm = "group:[email protected]";

        _pubsubFixture.CreateTopic(topicId);
        _pubsubFixture.CreateSubscription(topicId, subscriptionId);

        _setSubscriptionIamPolicySample.SetSubscriptionIamPolicy(_pubsubFixture.ProjectId, subscriptionId, testRoleValueToConfirm, testMemberValueToConfirm);

        var response = _testSubscriptionIamPermissionsSample.TestSubscriptionIamPermissionsResponse(_pubsubFixture.ProjectId, subscriptionId);

        Assert.NotEmpty(response.ToString());
    }
    public async void PullMessagesWithCustomAttributesAsync()
    {
        string randomName     = _pubsubFixture.RandomName();
        string topicId        = $"testTopicForMessagesWithPullCustomAttributesAsync{randomName}";
        string subscriptionId = $"testSubscriptionMessagesPullWithCustomAttributesAsync{randomName}";
        string message        = _pubsubFixture.RandomName();

        _pubsubFixture.CreateTopic(topicId);
        _pubsubFixture.CreateSubscription(topicId, subscriptionId);

        await _publishMessageWithCustomAttributesAsyncSample.PublishMessageWithCustomAttributesAsync(_pubsubFixture.ProjectId, topicId, message);

        var messages = await _pullMessagesWithCustomAttributesAsyncSample.PullMessagesWithCustomAttributesAsync(_pubsubFixture.ProjectId, subscriptionId, true);

        Assert.Contains(messages, m => m.Attributes.Keys.Contains("year") && m.Attributes.Values.Contains("2020"));
    }
Пример #14
0
    public async void PullMessageWithLeaseManagement()
    {
        string randomName     = _pubsubFixture.RandomName();
        string topicId        = $"testTopicForMessageWithLeaseManagement{randomName}";
        string subscriptionId = $"testSubscriptionForMessageWithLeaseManagement{randomName}";

        _pubsubFixture.CreateTopic(topicId);
        _pubsubFixture.CreateSubscription(topicId, subscriptionId);

        await _publishMessagesAsyncSample.PublishMessagesAsync(_pubsubFixture.ProjectId, topicId, new string[] { "Hello World!", "Good day.", "Bye bye." });

        // Pull and acknowledge the messages
        var messageCount = _pullMessageWithLeaseManagementSample.PullMessageWithLeaseManagement(_pubsubFixture.ProjectId, subscriptionId, true);

        Assert.Equal(3, messageCount);
    }
    public async void PublishMessageWithRetrySettingsAsync()
    {
        string randomName     = _pubsubFixture.RandomName();
        string topicId        = $"testTopicForMessageWithRetrySettingsAsync{randomName}";
        string subscriptionId = $"testSubscriptionForMessageWithRetrySettingsAsync{randomName}";

        _pubsubFixture.CreateTopic(topicId);
        _pubsubFixture.CreateSubscription(topicId, subscriptionId);

        await _publishMessageWithRetrySettingsAsyncSample
        .PublishMessageWithRetrySettingsAsync(_pubsubFixture.ProjectId, topicId, "Hello World!");

        // Pull the Message to confirm it is valid
        var messageCount = await _pullMessagesAsyncSample.PullMessagesAsync(_pubsubFixture.ProjectId, subscriptionId, true);

        Assert.Equal(1, messageCount);
    }
Пример #16
0
    public async void AcknowledgeMessageWithFlowControl()
    {
        string topicId        = "testTopicForMessageWithFlowControlAck" + _pubsubFixture.RandomName();
        string subscriptionId = "testSubscriptionForMessageWithFlowControlAck" + _pubsubFixture.RandomName();
        var    message        = _pubsubFixture.RandomName();

        _pubsubFixture.CreateTopic(topicId);
        _pubsubFixture.CreateSubscription(topicId, subscriptionId);

        await _publishMessagesAsyncSample.PublishMessagesAsync(_pubsubFixture.ProjectId, topicId, new string[] { message });

        // Pull and acknowledge the messages
        var result = await _pullMessagesCustomAsyncSample.PullMessagesWithFlowControlAsync(_pubsubFixture.ProjectId, subscriptionId, true);

        Assert.Equal(1, result);

        //Pull the Message to confirm it's gone after it's acknowledged
        result = await _pullMessagesCustomAsyncSample.PullMessagesWithFlowControlAsync(_pubsubFixture.ProjectId, subscriptionId, true);

        Assert.True(result == 0);
    }
Пример #17
0
    public async void PublishMessage()
    {
        string topicId        = "testTopicForMessageCreation" + _pubsubFixture.RandomName();
        string subscriptionId = "testSubscriptionForMessageCreation" + _pubsubFixture.RandomName();

        _pubsubFixture.CreateTopic(topicId);
        _pubsubFixture.CreateSubscription(topicId, subscriptionId);

        List <string> messageTexts = new List <string> {
            "Hello World!", "Good day.", "Bye bye."
        };

        var output = await _publishMessagesAsyncSample.PublishMessagesAsync(_pubsubFixture.ProjectId, topicId, messageTexts);

        Assert.Equal(messageTexts.Count, output);

        // Pull the Message to confirm it is valid
        var result = await _pullMessagesAsyncSample.PullMessagesAsync(_pubsubFixture.ProjectId, subscriptionId, false);

        Assert.True(result > 0);
    }
    public async void PullMessagesSync()
    {
        string topicId        = "testTopicForMessageSyncAck" + _pubsubFixture.RandomName();
        string subscriptionId = "testSubscriptionForMessageSyncAck" + _pubsubFixture.RandomName();
        var    message        = _pubsubFixture.RandomName();

        _pubsubFixture.CreateTopic(topicId);
        _pubsubFixture.CreateSubscription(topicId, subscriptionId);

        await _publishMessagesAsyncSample.PublishMessagesAsync(_pubsubFixture.ProjectId, topicId, new string[] { message });

        // Pull and acknowledge the messages
        var result = _pullMessagesSyncSample.PullMessagesSync(_pubsubFixture.ProjectId, subscriptionId, true);

        // sometimes UNAVAILABLE response from service.
        Assert.True(result <= 1);

        //Pull the Message to confirm it's gone after it's acknowledged
        result = _pullMessagesSyncSample.PullMessagesSync(_pubsubFixture.ProjectId, subscriptionId, true);
        Assert.True(result <= 1);
    }
    public async void PublishMessage()
    {
        string randomName     = _pubsubFixture.RandomName();
        string topicId        = $"testTopicForOrderedPublish{randomName}";
        string subscriptionId = $"testSubscriptionForOrderedPublish{randomName}";

        _pubsubFixture.CreateTopic(topicId);
        _pubsubFixture.CreateSubscription(topicId, subscriptionId);

        List <(string, string)> messages = new List <(string, string)> {
            ("Key1", "Hello World!"), ("Key2", "Good day."), ("Key1", "Bye bye")
        };

        var publishedMessages = await _publishOrderedMessagesAsyncSample.PublishOrderedMessagesAsync(_pubsubFixture.ProjectId, topicId, messages);

        Assert.Equal(messages.Count, publishedMessages);

        // Pull the Message to confirm it is valid
        var messagesPulled = await _pullMessagesAsyncSample.PullMessagesAsync(_pubsubFixture.ProjectId, subscriptionId, false);

        Assert.True(messagesPulled > 0);
    }
    public async Task PullMessagesAsync()
    {
        string randomName     = _pubsubFixture.RandomName();
        string topicId        = $"testTopicForMessageAck{randomName}";
        string subscriptionId = $"testSubscriptionForMessageAck{randomName}";
        var    message        = _pubsubFixture.RandomName();

        _pubsubFixture.CreateTopic(topicId);
        _pubsubFixture.CreateSubscription(topicId, subscriptionId);

        await _publishMessagesAsyncSample.PublishMessagesAsync(_pubsubFixture.ProjectId, topicId, new string[] { message });

        await _pubsubFixture.Pull.Eventually(async() =>
        {
            // Pull and acknowledge the messages
            var result = await _pullMessagesAsyncSample.PullMessagesAsync(_pubsubFixture.ProjectId, subscriptionId, true);
            Assert.Equal(1, result);
        });

        //Pull the Message to confirm it's gone after it's acknowledged
        var result = await _pullMessagesAsyncSample.PullMessagesAsync(_pubsubFixture.ProjectId, subscriptionId, true);

        Assert.Equal(0, result);
    }
Пример #21
0
    public async Task PublishBatchMessagesAsync()
    {
        string randomName     = _pubsubFixture.RandomName();
        string topicId        = $"testTopicForBatchMessageCreation{randomName}";
        string subscriptionId = $"testSubscriptionForBatchMessageCreation{randomName}";

        _pubsubFixture.CreateTopic(topicId);
        _pubsubFixture.CreateSubscription(topicId, subscriptionId);

        List <string> messageTexts = new List <string> {
            "Hello World!", "Good day.", "Bye bye."
        };

        var output = await _publishBatchedMessagesAsyncSample.PublishBatchMessagesAsync(_pubsubFixture.ProjectId, topicId, messageTexts);

        Assert.Equal(messageTexts.Count, output);

        // Pull the Message to confirm it is valid
        await _pubsubFixture.Pull.Eventually(async() =>
        {
            var result = await _pullMessagesAsyncSample.PullMessagesAsync(_pubsubFixture.ProjectId, subscriptionId, false);
            Assert.True(result > 0);
        });
    }