From cc0e3e441b1b74a2157b3ffdd3759977900c3fea Mon Sep 17 00:00:00 2001 From: mventura Date: Thu, 12 Oct 2017 11:58:25 +0200 Subject: [PATCH 1/3] refs #10 - Add command to start a workflow --- Library/Commands/Workflow.php | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Library/Commands/Workflow.php diff --git a/Library/Commands/Workflow.php b/Library/Commands/Workflow.php new file mode 100644 index 0000000..67aa7d0 --- /dev/null +++ b/Library/Commands/Workflow.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Disturb\Commands; + +class Workflow +{ + /** + * Start workflow by sending a message in related topic + * + * @param String $workflowName Workflow name + * @param String $workflowId Workflow id + * @param Array $payloadHash List of params + * + */ + public static function start(string $workflowName, string $workflowId, array $payloadHash) + { + $brokers = 'localhost'; + $msg = '{"contract":"'.$workflowId.'", "type" : "WF-CONTROL", "action":"start"}'; + + //send message with givens params + $kafkaProducer = new \RdKafka\Producer(); + $kafkaProducer->addBrokers($brokers); + $topicName = 'disturb-' . $workflowName . '-manager'; //xxx create service to manage topic name + + $kafkaTopic = $kafkaProducer->newTopic($topicName); + $kafkaTopic->produce(RD_KAFKA_PARTITION_UA, 0, "$msg"); + } +} From 5b064258b96e81b159f28ab7b7c18b5b25a3c288 Mon Sep 17 00:00:00 2001 From: mventura Date: Fri, 20 Oct 2017 15:07:59 +0200 Subject: [PATCH 2/3] refs #10 - Using DTO message --- Library/Commands/Workflow.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Library/Commands/Workflow.php b/Library/Commands/Workflow.php index 67aa7d0..83f81a2 100644 --- a/Library/Commands/Workflow.php +++ b/Library/Commands/Workflow.php @@ -8,7 +8,9 @@ * file that was distributed with this source code. */ -namespace Disturb\Commands; +namespace Vpg\Disturb\Commands; + +use \Vpg\Disturb\Dtos; class Workflow { @@ -23,7 +25,14 @@ class Workflow public static function start(string $workflowName, string $workflowId, array $payloadHash) { $brokers = 'localhost'; - $msg = '{"contract":"'.$workflowId.'", "type" : "WF-CONTROL", "action":"start"}'; + + $messageHash = [ + 'id' => $workflowId, + 'type' => Dtos\Message::TYPE_WF_CTRL, + 'action' => 'start', + 'payload' => $payloadHash + ]; + $stepMessageDto = new Dtos\Message(json_encode($messageHash)); //send message with givens params $kafkaProducer = new \RdKafka\Producer(); @@ -31,6 +40,6 @@ public static function start(string $workflowName, string $workflowId, array $pa $topicName = 'disturb-' . $workflowName . '-manager'; //xxx create service to manage topic name $kafkaTopic = $kafkaProducer->newTopic($topicName); - $kafkaTopic->produce(RD_KAFKA_PARTITION_UA, 0, "$msg"); + $kafkaTopic->produce(RD_KAFKA_PARTITION_UA, 0, "$stepMessageDto"); } } From 28ccf0afb45f1b720c564548f6ff19c0aff40c08 Mon Sep 17 00:00:00 2001 From: mventura Date: Fri, 3 Nov 2017 12:02:19 +0100 Subject: [PATCH 3/3] #10 - CR --- Library/Commands/{Workflow.php => WorkflowCommand.php} | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) rename Library/Commands/{Workflow.php => WorkflowCommand.php} (89%) diff --git a/Library/Commands/Workflow.php b/Library/Commands/WorkflowCommand.php similarity index 89% rename from Library/Commands/Workflow.php rename to Library/Commands/WorkflowCommand.php index 83f81a2..ed767f6 100644 --- a/Library/Commands/Workflow.php +++ b/Library/Commands/WorkflowCommand.php @@ -11,8 +11,9 @@ namespace Vpg\Disturb\Commands; use \Vpg\Disturb\Dtos; +use \Vpg\Disturb\Services\TopicService; -class Workflow +class WorkflowCommand { /** * Start workflow by sending a message in related topic @@ -37,7 +38,7 @@ public static function start(string $workflowName, string $workflowId, array $pa //send message with givens params $kafkaProducer = new \RdKafka\Producer(); $kafkaProducer->addBrokers($brokers); - $topicName = 'disturb-' . $workflowName . '-manager'; //xxx create service to manage topic name + $topicName = TopicService::getWorkflowManagerTopicName($workflowName); $kafkaTopic = $kafkaProducer->newTopic($topicName); $kafkaTopic->produce(RD_KAFKA_PARTITION_UA, 0, "$stepMessageDto");