Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Messenger] Add a "in-memory://" transport#29097

Merged
fabpot merged 2 commits intosymfony:masterfrom
GaryPEGEOT:feature/null-transporter
Apr 6, 2019
Merged

[Messenger] Add a "in-memory://" transport#29097
fabpot merged 2 commits intosymfony:masterfrom
GaryPEGEOT:feature/null-transporter

Conversation

@GaryPEGEOT
Copy link
Contributor

@GaryPEGEOT GaryPEGEOT commented Nov 5, 2018

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #29040
License MIT
Doc PR Todo

Add a new InMemoryTransport for test purpose, usable by starting your DSN by in-memory://

@ogizanagi
Copy link
Contributor

ogizanagi commented Nov 5, 2018

Just a random thought: Isn't a null transport just a special case of a memory transport without any listener?

@ogizanagi
Copy link
Contributor

Note regarding #29097 (comment): that would mean making the MemoryTransport MessageBusInterface $bus constructor argument optional or extract dispatch in a dedicated listener.
No strong opinion yet.

@nicolas-grekas nicolas-grekas added this to the next milestone Nov 6, 2018
@javiereguiluz
Copy link
Member

@GaryPEGEOT thanks for this contribution! If this is finally merged, please review the list of Messenger issues and list of pending Messenger pull requests to see if there are issues/PRs conflicting with this change. If there are not, please open an issue in https://github.com/symfony/symfony-docs/issues to track this change. You don't have to provide the docs yourself if you don't want, but this would help us track the change. Thanks!

Copy link
Contributor

@sroze sroze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except these stylish details to be changed, looks good to me 👍

@stof
Copy link
Member

stof commented Mar 20, 2019

Just a random thought: Isn't a null transport just a special case of a memory transport without any listener?

If you never flush your MemoryTransport, it would leak memory. So using it instead of a NullTransport looks wrong (having to flush something when you expect it to be a blackhole is not intuitive)

*/
public function send(Envelope $envelope): Envelope
{
$this->sent[] = $envelope;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we accumulate envelopes over time, do we need to implement ResetableInterface to flush the envelopes from one request to the next?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sroze, @fabpot I've implemented Symfony\Contracts\Service\ResetInterface and I now see that there is an ack an reject method in the Transport interface. Do you think we need to store which message has been ack / nack?

@ogizanagi
Copy link
Contributor

ogizanagi commented Mar 21, 2019

having to flush something when you expect it to be a blackhole is not intuitive)

But it's not just a blackhole (null transport might be misleading in this way): this transport is storing the sent envelopes (to be used in tests for instance). So I would have implemented ResetableInterface on the MemoryTransport and just use a different factory registering it.

@sroze
Copy link
Contributor

sroze commented Mar 23, 2019

@GaryPEGEOT can you implement the ResetableInterface and test that the messages are properly removed?

@sroze
Copy link
Contributor

sroze commented Mar 23, 2019 via email

@GaryPEGEOT
Copy link
Contributor Author

@sroze I added the getAcknowledged and getRejected methods

*
* @author Gary PEGEOT <[email protected]>
*/
class NullTransport implements TransportInterface, ResetInterface
Copy link
Contributor

@ogizanagi ogizanagi Mar 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note implementing ResetInterface isn't enough for this to be properly integrated with the framework and stored envelopes to be cleared from one request to the next. The service definition must be tagged with kernel.reset.

But as the service is built using a factory and might use an env var for the DSN, it may not be possible to add the tag conditionally from the extension (compile time). Instead, you could implement ResetInterface on the factory too and keep track of created services to clear them from here (so only the factory will be tagged with kernel.reset).

*
* @author Gary PEGEOT <[email protected]>
*/
class NullTransportFactoryTest extends \PHPUnit\Framework\TestCase
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe worth importing TestCase?
use PHPUnit\Framework\TestCase;

@fabpot
Copy link
Member

fabpot commented Mar 31, 2019

I agree with @ogizanagi that I would not expect a null transport to store things.

@sroze
Copy link
Contributor

sroze commented Mar 31, 2019

in-memory://?

@weaverryan
Copy link
Contributor

Well, we also have #28746, which is a "memory" transport where the messages are sent on kernel.terminate. Probably we should only merge one... call it memory:// (?), and have the "send on kernel.terminate` part configurable, so that you could use it for testing (and not handle on kernel.terminate) or decide that you DO want to send it using that.

@sroze
Copy link
Contributor

sroze commented Mar 31, 2019

I agree it should be the same implementation. Though... it could actually be two DSNs in-memory:// & symfony://kernel.terminate IMHO. Let's make this one just in-memory:// and ask the kernel.terminate to be changed to update this transport. WDYT?

@GaryPEGEOT
Copy link
Contributor Author

Should it be a black-hole and do nothing at all (no storing nor receiving of message) to avoid duplication with memory listener?

@sroze
Copy link
Contributor

sroze commented Mar 31, 2019

to avoid duplication with memory listener

What do you mean? 🤔

@GaryPEGEOT
Copy link
Contributor Author

to avoid duplication with memory listener

What do you mean? thinking

memory transport, my bad!, both this transport and the one in #28746 store message in memory, so are kind of duplicate. Should this one do nothing instead, ie not storing any message?

@weaverryan
Copy link
Contributor

I think the idea is this: This one SHOULD store in memory, and be called in-memory. And then #28746 could actually use this transport behind the scenes to read the stored messages and send them.

@sroze
Copy link
Contributor

sroze commented Mar 31, 2019

Exactly 👍

@GaryPEGEOT
Copy link
Contributor Author

I think the idea is this: This one SHOULD store in memory, and be called in-memory. And then #28746 could actually use this transport behind the scenes to read the stored messages and send them.

Renamed to InMemoryTransport, as well as the dsn

@GaryPEGEOT GaryPEGEOT changed the title [Messenger] Add a "null://" transport [Messenger] Add a "in-memory://" transport Mar 31, 2019
use Symfony\Contracts\Service\ResetInterface;

/**
* Transport that stay in memory. Useful for testing purpose.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stays

@fabpot
Copy link
Member

fabpot commented Apr 6, 2019

Thank you @GaryPEGEOT.

@fabpot fabpot merged commit 8f8c82e into symfony:master Apr 6, 2019
fabpot added a commit that referenced this pull request Apr 6, 2019
…, sroze)

This PR was merged into the 4.3-dev branch.

Discussion
----------

[Messenger] Add a "in-memory://" transport

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #29040
| License       | MIT
| Doc PR        | Todo

Add a new `InMemoryTransport` for test purpose, usable by starting your DSN by `in-memory://`

Commits
-------

8f8c82e Make the in-memory transport resettable
fe75920 Add a "null://" transport
Copy link
Member

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

#eu-fossa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.