Publishing and Sync Tutorial issue


#1

Hello,

actually I wanted to use this tutorial

https://documentation.spryker.com/tutorials/introduction/handling-data-publish-and-synchronization.htm

for my own use case. But it does not work, so i decided to do the full tutorial. But this also does not work.
I stuck on

After running the code, open the web interface of Spryker queue adapter, RabbitMQ (http://zed.de.suite.local:15672/#/queues). You should be able to see one event in the Event Queue:

The problem is, i don’t get any new event queues. I checked, that the getSubscribedEvents Method is called after running code from my controller, but nothing does happen.

  1. What can be the problem?

  2. Why i have to disable jenkins to see any results? (like described in the tutorial) Shouldn’t it be enabled afterwards?

  3. Why the spy_hello_world_message scheme is in the HelloWorldStorage Module and not in the HelloWorld Module?

Best regards


#2

Hi,

What can be the problem?

First please check your exception.log and see if there is any error.

Events will go to a temporary table before they go to queue, please check if you don’t have any event stuck in this table spy_event_behavior_entity_change. if everything works fine the table should be empty otherwise you have an error and it should be shown in exception.log

Why i have to disable jenkins to see any results? (like described in the tutorial) Shouldn’t it be enabled afterwards?

Jenkins is responsible to run the all spryker jobs (Mail, Queue, OMS, etc), when you have jenkins enabled, Queue worker command will be executed in the background and will consume the messages, this happens very fast and you can’t see any event for any debugging purpose.

Note: Jenkins should be enabled by default, we only disable it if we want to debug the process.

Why the spy_hello_world_message scheme is in the HelloWorldStorage Module and not in the HelloWorld Module?

This is wrong, I’ll create a ticket to update the tutorial.

Thank you so much for your feedback, please let me know if you have any further questions
Ehsan Zanjani


#3

Hi @ehsan.zanjani,

thanks for your fast response. I tried again and there was indeed an error concerning the queue in the error.log. In detail the namespace was wrong (typical fail through copy) as it is still the Spryker Namespace instead Pyz in the documentation.
I changed it and the error is gone but there is still no

sync.storage.hello queue …

Could it be, that simply the image is wrong? I can see now a message in the “event” queue with the corresponding content mentioned in the tutorial, but not a “sync.storage.hello” queue.

Thanks, that was the missing part for understanding and thanks for keeping up improvements.

Best regards


#4

Finally, i tried to transfer the things to my “real” use case … now i got the mentioned entry in

spy_event_behavior_entity_change

But i have no error.log. I deleted all error.log log files and no error.log was created again. So i think, there is no error :confused:

I did exactly the same as in the tutorial.

Update:

I found out, that creating a new entity from my business model in my “real” code does not work (ends up in the database entry) but executing exactly the same line from the helloworld tutorial will work.

(new PyzTestDevice())->setTestDeviceId(md5(time()))->setDeviceName("test")->save();

in my

DeviceWriter Business Model will cause the erroneous database entry

but

(new PyzTestDevice())->setTestDeviceId(md5(time()))->setDeviceName("test")->save();

in IndexController of the tutorial (Pyz\Zed\HelloWorld\Communication\Controller) will trigger the expected behavior (queue entry).

:confused: now i am totally confused

Edit 2:

Another difference is that the tutorial example is triggered over the php-fpm (http-request) and my real case is triggered by a cli command … maybe this could be the problem?

The database entry in spy_event_behavior_entity_change looks like this

55038 {“name”:“pyz_test_device”,“id”:12,“event”:“Entity.pyz_test_device.create”,“foreignKeys”:[],“modifiedColumns”:[“pyz_test_device.test_device_id”,“pyz_test_device.device_name”]} cli-spryker-vagrant-51875c486eb31ffd59.58933414 2019-01-23 13:40:03.14562


#5

H @JimPanse,

sync.storage.hello queue is empty

When you trigger the event, one or many messages will go to event queue, but this is just one part, the next step is to run the console queue:task:start event for consuming the events and save them into the storage table in database and also send a copy of data to sync.queue.

Another difference is that the tutorial example is triggered over the php-fpm (http-request) and my real case is triggered by a cli command … maybe this could be the problem?

There are two classes which are responsible to read the entries and send them to the event queue.

  1. php-fpm : Spryker\Zed\EventBehavior\Communication\Plugin\ServiceProvider\EventBehaviorServiceProvider which needs to be registered in Zed/YvesBootstrap
  2. cli : Spryker\Zed\EventBehavior\Communication\Plugin\Console\EventBehaviorPostHookPlugin which needs to be added in getConsolePostRunHookPlugins() in ConsoleDependencyProvider

#6

The are registered on both places. Nevertheless i guess that is has something to do with this. My consoleapplication is running a loop all the time and triggers an callback function on a specific event.

So maybe some postHook is never executed cause the script is still in the loop? Is the postRunHookPlugin stuff called at the end of the script?

Edit:
My guess seems to be true. If i set a breakpoint for the helloworld example in the index controller on the ->save() line and go just one step further, the entity is saved and an entry was created for fpm in the event_behavior table. If i run the rest of the code, the entry in the behavior table is immediately picked up and the script finished.

But my cli command does not finish because it has to run as long as its not killed. Is there maybe a possibility to manual trigger the event to pick up the event_behavior_… table entries?

Best reagrds


#7

Hi Jim,

Yes these classes will be executed at the end of the execution process.

You can just call it manually by using this facade API after you reach the end of each iteration in the loop:
$this->getFacade()->triggerRuntimeEvents();

This should solve your problem


#8

Hi @ehsan.zanjani,
this issue should be resolved by your suggestion and it was a bit annoying but it also shows me a flaw of my design.
I should go for a solution where a queue is involved so my never-ending loop can work without being blocked by expensive database operations.

Thanks for your help!

Best regards