简体   繁体   中英

How to cancel dispatched message in Symfony 5?

I have an app for parsing sites. The parsing process has several statuses. When a user initializes a process, the status is Running . When a user stops the process, it is switched to Cancelled .

When the process is running it dispatches a lot of events (for each category and product). And when the process is cancelled, all of those events should be ignored / deleted.

My approach is just to check if a process is stopped in each event handler. Of course, it brings a lot of redundant code. Moreover, it just simply makes additional load on the server because a worker should dispatch all of those unnecessary events even if those events will not do anything. Just to say, each handler will have to make a DB query to check the process' status.

I am new to Symfony's Messenger so I suppose there is a more elegant solution. I know about middlewares, stamps. But can not utilize them for my problem.

If Symfony Messenger you can not stop to invoke all handlers .

But in EventDispatcher is possible via the stopPropagation() method .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM