Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions Library/Commands/WorkflowCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?
/*
* This file is part of the Disturb package.
*
* (c) Matthieu Ventura <mventura@voyageprive.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Vpg\Disturb\Commands;

use \Vpg\Disturb\Dtos;
use \Vpg\Disturb\Services\TopicService;

class WorkflowCommand
{
/**
* 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';

$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();
$kafkaProducer->addBrokers($brokers);
$topicName = TopicService::getWorkflowManagerTopicName($workflowName);

$kafkaTopic = $kafkaProducer->newTopic($topicName);
$kafkaTopic->produce(RD_KAFKA_PARTITION_UA, 0, "$stepMessageDto");
}
}