Skip to content

Commit 36fec00

Browse files
committed
Merge branch 'next-14363/webhook-dispatching-over-queue' into 'trunk'
NEXT-14363 - Webhook dispatching over queue See merge request shopware/6/product/platform!4999
2 parents 730a28b + e249a8c commit 36fec00

9 files changed

+469
-48
lines changed

changelog/_unreleased/2021-03-31-add-the-current-sw-version-to-all-outgoing-request-to-external-apps.md

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
title: Add the current sw version to all outgoing request to external apps
33
issue: NEXT-14359
4-
flag: FEATURE_NEXT_13992
54
---
65
# Core
76
* Changed method `execute` in `src/Core/Framework/App/ActionButton/Executor.php` to add `shopware version` to `action button requests`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: Webhook dispatching over queue
3+
issue: NEXT-14363
4+
flag: FEATURE_NEXT_14363
5+
---
6+
# Core
7+
* Added `src\Core\Framework\Webhook\Message\WebhookEventMessage` class
8+
* Added `src\Core\Framework\Webhook\Handler\WebhookEventMessageHandler` class
9+
* Changed method `callWebhooks` in `src\Core\Framework\Webhook\WebhookDispatcher` to handle webhooks asynchronous over the queue

src/Core/Framework/DependencyInjection/webhook.xml

+9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<argument type="service" id="service_container"/>
1414
<argument type="service" id="Shopware\Core\Framework\Webhook\Hookable\HookableEventFactory"/>
1515
<argument>%kernel.shopware_version%</argument>
16+
<argument type="service" id="Symfony\Component\Messenger\MessageBusInterface"/>
1617
</service>
1718

1819
<service id="Shopware\Core\Framework\Webhook\WebhookCacheClearer">
@@ -43,5 +44,13 @@
4344
<argument type="service" id="Shopware\Core\Framework\Event\BusinessEventCollector"/>
4445
<argument type="service" id="Shopware\Core\Framework\DataAbstractionLayer\DefinitionInstanceRegistry"/>
4546
</service>
47+
48+
<service id="Shopware\Core\Framework\Webhook\Handler\WebhookEventMessageHandler">
49+
<argument type="service" id="shopware.app_system.guzzle"/>
50+
<argument type="service" id="app.repository"/>
51+
52+
<tag name="messenger.message_handler"/>
53+
<tag name="shopware.feature" flag="FEATURE_NEXT_14363"/>
54+
</service>
4655
</services>
4756
</container>

src/Core/Framework/Resources/config/packages/shopware.yaml

+3-4
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,17 @@ shopware:
118118
major: false
119119
description: "App System 3.0 - Payments"
120120
# issue: NEXT-14357
121-
- name: FEATURE_NEXT_13992
121+
- name: FEATURE_NEXT_14363
122122
default: false
123123
major: false
124-
description: "App System 3.0"
125-
# issue: NEXT-13992
124+
description: "App System 3.0 - Dispatch webhook overqueue"
125+
# issue: NEXT-14363
126126
- name: FEATURE_NEXT_12654
127127
default: false
128128
major: false
129129
description: "Preview available variables of email templates in the administration"
130130
# issue: NEXT-12654
131131

132-
133132
logger:
134133
file_rotation_count: 14
135134

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Shopware\Core\Framework\Test\Webhook\Handler;
4+
5+
use GuzzleHttp\Psr7\Response;
6+
use PHPUnit\Framework\TestCase;
7+
use Shopware\Core\Framework\Context;
8+
use Shopware\Core\Framework\Feature;
9+
use Shopware\Core\Framework\Test\App\GuzzleTestClientBehaviour;
10+
use Shopware\Core\Framework\Test\TestCaseBase\IntegrationTestBehaviour;
11+
use Shopware\Core\Framework\Uuid\Uuid;
12+
use Shopware\Core\Framework\Webhook\Handler\WebhookEventMessageHandler;
13+
use Shopware\Core\Framework\Webhook\Message\WebhookEventMessage;
14+
15+
class WebhookEventMessageHandlerTest extends TestCase
16+
{
17+
use IntegrationTestBehaviour;
18+
use GuzzleTestClientBehaviour;
19+
20+
private WebhookEventMessageHandler $webhookEventMessageHandler;
21+
22+
public function setUp(): void
23+
{
24+
Feature::skipTestIfInActive('FEATURE_NEXT_14363', $this);
25+
$this->webhookEventMessageHandler = $this->getContainer()->get(WebhookEventMessageHandler::class);
26+
}
27+
28+
public function testGetHandledMessages(): void
29+
{
30+
/** @var array $subscribedMessages */
31+
$subscribedMessages = $this->webhookEventMessageHandler::getHandledMessages();
32+
33+
static::assertCount(1, $subscribedMessages);
34+
static::assertEquals(WebhookEventMessage::class, $subscribedMessages[0]);
35+
}
36+
37+
public function testSendSuccessful(): void
38+
{
39+
$webhookId = Uuid::randomHex();
40+
$appId = Uuid::randomHex();
41+
42+
$appRepository = $this->getContainer()->get('app.repository');
43+
$appRepository->create([[
44+
'id' => $appId,
45+
'name' => 'SwagApp',
46+
'active' => true,
47+
'path' => __DIR__ . '/Manifest/_fixtures/test',
48+
'version' => '0.0.1',
49+
'label' => 'test',
50+
'appSecret' => 's3cr3t',
51+
'integration' => [
52+
'label' => 'test',
53+
'writeAccess' => false,
54+
'accessKey' => 'api access key',
55+
'secretAccessKey' => 'test',
56+
],
57+
'aclRole' => [
58+
'name' => 'SwagApp',
59+
],
60+
'webhooks' => [
61+
[
62+
'id' => $webhookId,
63+
'name' => 'hook1',
64+
'eventName' => 'order',
65+
'url' => 'https://test.com',
66+
],
67+
],
68+
]], Context::createDefaultContext());
69+
70+
$this->appendNewResponse(new Response(200));
71+
72+
(($this->webhookEventMessageHandler)(new WebhookEventMessage(['payload'], $appId, $webhookId, '6.4', 'https://test.com')));
73+
74+
$request = $this->getLastRequest();
75+
static::assertEquals('POST', $request->getMethod());
76+
$body = $request->getBody()->getContents();
77+
static::assertEquals($body, json_encode(['payload']));
78+
static::assertTrue($request->hasHeader('sw-version'));
79+
static::assertEquals($request->getHeaderLine('sw-version'), '6.4');
80+
}
81+
}

0 commit comments

Comments
 (0)