GithubHelp home page GithubHelp logo

Comments (5)

byrnedo avatar byrnedo commented on June 16, 2024

Hi @tommyseus,

What version of nats streaming is it?

Could you explain your use case and flow that triggers this?

from php-nats-streaming.

tommyseus avatar tommyseus commented on June 16, 2024

I'm sorry, the exception has a different cause.

The error is triggered by the next message. There are 2 messages published. But the subscribe handles only one (wait (1)) and than unsubscribed from the subject. Between wait and unsubscribe the second message has arrieved. I have added a sleep so that the error always occurs for demonstration.

publisher.php :

<?php

require __DIR__ . '/vendor/autoload.php';

ini_set('display_errors', '1');

$options = new Nats\ConnectionOptions();
$options->setHost('da-nats-streaming');

$streamingOptions = new \NatsStreaming\ConnectionOptions();
$streamingOptions->setClientID(uniqid('test_', false));
$streamingOptions->setClusterID("test-cluster");
$streamingOptions->setNatsOptions($options);

$streamingConnection = new \NatsStreaming\Connection($streamingOptions);
$streamingConnection->connect(60);

// publish

for ($i = 1; $i <= 4; ++$i) {
    $request = $streamingConnection->publish('dummy-subject', "publish $i  - " . date('Y-m-d H:i:s'));
    $request->wait();
    var_dump($request->gotAck());
}

subscriber.php :

<?php

require __DIR__ . '/vendor/autoload.php';

ini_set('display_errors', '1');

$options = new Nats\ConnectionOptions();
$options->setHost('da-nats-streaming');

$streamingOptions = new \NatsStreaming\ConnectionOptions();
$streamingOptions->setClientID(uniqid('dummy-client-id'));
$streamingOptions->setClusterID("test-cluster");
$streamingOptions->setNatsOptions($options);

$streamingConnection = new \NatsStreaming\Connection($streamingOptions);
$streamingConnection->connect(60);

// subscribe

$subscriptionOptions = new NatsStreaming\SubscriptionOptions();
$subscriptionOptions->setAckWaitSecs(10);
$subscriptionOptions->setManualAck(true);
$subscriptionOptions->setDurableName('dummy-durable');
$subscriptionOptions->setMaxInFlight(1);

$subscribe = $streamingConnection->queueSubscribe(
    'dummy-subject',
    'abcdefghijkl',
    function ($message) {
        /* @var $message \NatsStreaming\Msg */
        echo 'received: ' . $message->getData() . PHP_EOL;
        $message->ack();
    },
    $subscriptionOptions
);
$subscribe->wait(1);

// time to receive the next message from the nats server
sleep(4);

// triggers a wait and consumes the next message. But throws a exception because the subscriber callback was removed.
$subscribe->unsubscribe();

Versions:
nats-streamin: 0.9.2 (https://hub.docker.com/_/nats-streaming/)
byrnedo/php-nats-streaming: 0.2.4
repejota/nats: 0.8.7

from php-nats-streaming.

byrnedo avatar byrnedo commented on June 16, 2024

from php-nats-streaming.

byrnedo avatar byrnedo commented on June 16, 2024

@tommyseus bump, have I grasped the flow?

from php-nats-streaming.

byrnedo avatar byrnedo commented on June 16, 2024

@tommyseus

from php-nats-streaming.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.