예제 #1
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);
        });
    }
예제 #2
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);
    }
예제 #3
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);
    }
    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);
    }
예제 #5
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 PullMessagesAsyncWithDeliveryAttempts()
    {
        string randomName     = _pubsubFixture.RandomName();
        string topicId        = $"testTopicForDeadLetterPolicyMessageSyncAck{randomName}";
        string subscriptionId = $"testSubscriptionDeadLetterPolicyForMessageSyncAck{randomName}";
        var    message        = _pubsubFixture.RandomName();

        _pubsubFixture.CreateTopic(topicId);
        _createSubscriptionWithDeadLetterPolicySample.CreateSubscriptionWithDeadLetterPolicy(
            _pubsubFixture.ProjectId, subscriptionId, topicId, _pubsubFixture.DeadLetterTopic);

        _pubsubFixture.TempSubscriptionIds.Add(subscriptionId);

        await _publishMessagesAsyncSample.PublishMessagesAsync(_pubsubFixture.ProjectId, topicId, new List <string> {
            message
        });

        // Pull and acknowledge the messages
        var deliveryAttempt = await _pullMessagesAsyncWithDeliveryAttemptsSample.PullMessagesAsyncWithDeliveryAttempts(_pubsubFixture.ProjectId, subscriptionId, true);

        Assert.True(deliveryAttempt > 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);
    }