-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Business interface examples * examples * example * examples
- Loading branch information
Showing
20 changed files
with
438 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
quickstart-examples/BusinessInterface/Asynchronous/composer.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"type": "ecotone-quickstart", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Dariusz Gafka", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"App\\BusinessInterface\\": "src" | ||
} | ||
}, | ||
"require": { | ||
"ecotone/lite-dbal-starter": "^1.0.1" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^9.5", | ||
"wikimedia/composer-merge-plugin": "^2.0" | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
"config": { | ||
"sort-packages": true, | ||
"allow-plugins": { | ||
"wikimedia/composer-merge-plugin": true | ||
} | ||
}, | ||
"extra": { | ||
"merge-plugin": { | ||
"include": [ | ||
"../../../packages/local_packages.json" | ||
] | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
quickstart-examples/BusinessInterface/Asynchronous/run_example.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
use App\WorkingWithAggregateDirectly\Command\ChangePrice; | ||
use App\WorkingWithAggregateDirectly\Command\RegisterProduct; | ||
use App\WorkingWithAggregateDirectly\Product; | ||
use App\WorkingWithAggregateDirectly\ProductRepository; | ||
use App\WorkingWithAggregateDirectly\ProductService; | ||
use Ecotone\Lite\EcotoneLiteApplication; | ||
use Enqueue\Dbal\DbalConnectionFactory; | ||
use PHPUnit\Framework\Assert; | ||
use Ramsey\Uuid\Uuid; | ||
|
||
require __DIR__ . "/vendor/autoload.php"; | ||
$messagingSystem = EcotoneLiteApplication::boostrap([DbalConnectionFactory::class => new DbalConnectionFactory(getenv('DATABASE_DSN') ? getenv('DATABASE_DSN') : 'pgsql://ecotone:secret@localhost:5432/ecotone')], pathToRootCatalog: __DIR__); | ||
|
||
$cacheService = $messagingSystem->getGatewayByName(\App\BusinessInterface\CacheService::class); | ||
|
||
$cacheService->set(new \App\BusinessInterface\CachedItem("pageViews", "12333", "data")); | ||
|
||
Assert::assertNull($cacheService->get("pageViews")); | ||
|
||
// running Message Consumer | ||
$messagingSystem->run('async', \Ecotone\Messaging\Endpoint\ExecutionPollingMetadata::createWithTestingSetup()); | ||
|
||
Assert::assertEquals('12333', $cacheService->get('pageViews')); | ||
echo "Cache set and get successfully\n"; |
16 changes: 16 additions & 0 deletions
16
quickstart-examples/BusinessInterface/Asynchronous/src/CacheService.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\BusinessInterface; | ||
|
||
use Ecotone\Messaging\Attribute\BusinessMethod; | ||
|
||
interface CacheService | ||
{ | ||
#[BusinessMethod('cache.set')] | ||
public function set(CachedItem $item): void; | ||
|
||
#[BusinessMethod('cache.get')] | ||
public function get(string $key): ?string; | ||
} |
14 changes: 14 additions & 0 deletions
14
quickstart-examples/BusinessInterface/Asynchronous/src/CachedItem.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\BusinessInterface; | ||
|
||
final readonly class CachedItem | ||
{ | ||
public function __construct( | ||
public string $key, | ||
public string $value | ||
) | ||
{} | ||
} |
26 changes: 26 additions & 0 deletions
26
quickstart-examples/BusinessInterface/Asynchronous/src/InMemoryCache.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\BusinessInterface; | ||
|
||
use Ecotone\Messaging\Attribute\Asynchronous; | ||
use Ecotone\Messaging\Attribute\ServiceActivator; | ||
|
||
final class InMemoryCache | ||
{ | ||
private array $items; | ||
|
||
#[Asynchronous("async")] | ||
#[ServiceActivator('cache.set', endpointId: "cache.set.endpoint")] | ||
public function set(CachedItem $item): void | ||
{ | ||
$this->items[$item->key] = $item->value; | ||
} | ||
|
||
#[ServiceActivator('cache.get')] | ||
public function get(string $key): ?string | ||
{ | ||
return $this->items[$key] ?? null; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
quickstart-examples/BusinessInterface/Asynchronous/src/MessagingConfiguration.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\BusinessInterface; | ||
|
||
use Ecotone\Dbal\DbalBackedMessageChannelBuilder; | ||
use Ecotone\Messaging\Attribute\ServiceContext; | ||
|
||
final readonly class MessagingConfiguration | ||
{ | ||
#[ServiceContext] | ||
public function asyncChannel(): DbalBackedMessageChannelBuilder | ||
{ | ||
return DbalBackedMessageChannelBuilder::create("async"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Business Interface | ||
|
||
This provides examples of how to use the business interface to interact with the system. | ||
|
||
1. [ServiceActivator](ServiceActivator) | ||
2. [Routing](Routing) | ||
3. [Asynchronous](Asynchronous) |
37 changes: 37 additions & 0 deletions
37
quickstart-examples/BusinessInterface/Routing/composer.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"type": "ecotone-quickstart", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Dariusz Gafka", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"App\\BusinessInterface\\": "src" | ||
} | ||
}, | ||
"require": { | ||
"ecotone/lite-dbal-starter": "^1.0.1" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^9.5", | ||
"wikimedia/composer-merge-plugin": "^2.0" | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
"config": { | ||
"sort-packages": true, | ||
"allow-plugins": { | ||
"wikimedia/composer-merge-plugin": true | ||
} | ||
}, | ||
"extra": { | ||
"merge-plugin": { | ||
"include": [ | ||
"../../../packages/local_packages.json" | ||
] | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
quickstart-examples/BusinessInterface/Routing/run_example.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
use App\WorkingWithAggregateDirectly\Command\ChangePrice; | ||
use App\WorkingWithAggregateDirectly\Command\RegisterProduct; | ||
use App\WorkingWithAggregateDirectly\Product; | ||
use App\WorkingWithAggregateDirectly\ProductRepository; | ||
use App\WorkingWithAggregateDirectly\ProductService; | ||
use Ecotone\Lite\EcotoneLiteApplication; | ||
use Enqueue\Dbal\DbalConnectionFactory; | ||
use PHPUnit\Framework\Assert; | ||
use Ramsey\Uuid\Uuid; | ||
|
||
require __DIR__ . "/vendor/autoload.php"; | ||
$messagingSystem = EcotoneLiteApplication::boostrap([DbalConnectionFactory::class => new DbalConnectionFactory(getenv('DATABASE_DSN') ? getenv('DATABASE_DSN') : 'pgsql://ecotone:secret@localhost:5432/ecotone')], pathToRootCatalog: __DIR__); | ||
|
||
$cacheService = $messagingSystem->getGatewayByName(\App\BusinessInterface\CacheService::class); | ||
|
||
$cacheService->set( | ||
new \App\BusinessInterface\CachedItem("pageViews", "12333", "data"), | ||
\App\BusinessInterface\CacheType::IN_MEMORY | ||
); | ||
|
||
Assert::assertEquals("12333", $cacheService->get("pageViews", \App\BusinessInterface\CacheType::IN_MEMORY)); | ||
Assert::assertNull($cacheService->get("pageViews", \App\BusinessInterface\CacheType::FILE_SYSTEM)); | ||
echo "Cache set and get successfully\n"; |
17 changes: 17 additions & 0 deletions
17
quickstart-examples/BusinessInterface/Routing/src/CacheService.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\BusinessInterface; | ||
|
||
use Ecotone\Messaging\Attribute\BusinessMethod; | ||
use Ecotone\Messaging\Attribute\Parameter\Header; | ||
|
||
interface CacheService | ||
{ | ||
#[BusinessMethod('cache.set')] | ||
public function set(CachedItem $item, #[Header('cache.type')] CacheType $type): void; | ||
|
||
#[BusinessMethod('cache.get')] | ||
public function get(string $key, #[Header('cache.type')] CacheType $type): ?string; | ||
} |
11 changes: 11 additions & 0 deletions
11
quickstart-examples/BusinessInterface/Routing/src/CacheType.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\BusinessInterface; | ||
|
||
enum CacheType: string | ||
{ | ||
case IN_MEMORY = 'in_memory'; | ||
case FILE_SYSTEM = 'file_system'; | ||
} |
14 changes: 14 additions & 0 deletions
14
quickstart-examples/BusinessInterface/Routing/src/CachedItem.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\BusinessInterface; | ||
|
||
final readonly class CachedItem | ||
{ | ||
public function __construct( | ||
public string $key, | ||
public string $value, | ||
) | ||
{} | ||
} |
29 changes: 29 additions & 0 deletions
29
quickstart-examples/BusinessInterface/Routing/src/CachingRouter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\BusinessInterface; | ||
|
||
use Ecotone\Messaging\Attribute\Parameter\Header; | ||
use Ecotone\Messaging\Attribute\Router; | ||
|
||
final readonly class CachingRouter | ||
{ | ||
#[Router('cache.set')] | ||
public function routeSet(#[Header('cache.type')] CacheType $type): string | ||
{ | ||
return match ($type) { | ||
CacheType::FILE_SYSTEM => 'cache.set.file_system', | ||
CacheType::IN_MEMORY => 'cache.set.in_memory', | ||
}; | ||
} | ||
|
||
#[Router('cache.get')] | ||
public function routeGet(#[Header('cache.type')] CacheType $type): string | ||
{ | ||
return match ($type) { | ||
CacheType::FILE_SYSTEM => 'cache.get.file_system', | ||
CacheType::IN_MEMORY => 'cache.get.in_memory', | ||
}; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
quickstart-examples/BusinessInterface/Routing/src/FileSystem/FileSystemCache.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\BusinessInterface\FileSystem; | ||
|
||
use App\BusinessInterface\CachedItem; | ||
use Ecotone\Messaging\Attribute\ServiceActivator; | ||
|
||
final readonly class FileSystemCache | ||
{ | ||
#[ServiceActivator('cache.set.file_system')] | ||
public function set(CachedItem $item): void | ||
{ | ||
file_put_contents('/tmp/' . $item->key, $item->value); | ||
} | ||
|
||
#[ServiceActivator('cache.get.file_system')] | ||
public function get(string $key): ?string | ||
{ | ||
$data = @file_get_contents('/tmp/' . $key); | ||
|
||
return $data === false ? null : $data; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
quickstart-examples/BusinessInterface/Routing/src/InMemory/InMemoryCache.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\BusinessInterface\InMemory; | ||
|
||
use App\BusinessInterface\CachedItem; | ||
use Ecotone\Messaging\Attribute\ServiceActivator; | ||
|
||
final class InMemoryCache | ||
{ | ||
private array $items; | ||
|
||
#[ServiceActivator('cache.set.in_memory')] | ||
public function set(CachedItem $item): void | ||
{ | ||
$this->items[$item->key] = $item->value; | ||
} | ||
|
||
#[ServiceActivator('cache.get.in_memory')] | ||
public function get(string $key): ?string | ||
{ | ||
return $this->items[$key] ?? null; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
quickstart-examples/BusinessInterface/ServiceActivator/composer.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"type": "ecotone-quickstart", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Dariusz Gafka", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"App\\BusinessInterface\\": "src" | ||
} | ||
}, | ||
"require": { | ||
"ecotone/lite-dbal-starter": "^1.0.1" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^9.5", | ||
"wikimedia/composer-merge-plugin": "^2.0" | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
"config": { | ||
"sort-packages": true, | ||
"allow-plugins": { | ||
"wikimedia/composer-merge-plugin": true | ||
} | ||
}, | ||
"extra": { | ||
"merge-plugin": { | ||
"include": [ | ||
"../../../packages/local_packages.json" | ||
] | ||
} | ||
} | ||
} |
Oops, something went wrong.