Exemplo n.º 1
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);
    }
    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);
    }