operationFactory = $operationFactory; $this->jsonSerializer = $jsonSerializer; $this->messageEncoder = $messageEncoder; $this->messageValidator = $messageValidator; $this->entityManager = $entityManager; } /** * @param $topicName * @param $entityParams * @param $groupId * @return mixed */ public function createByTopic($topicName, $entityParams, $groupId) { $this->messageValidator->validate($topicName, $entityParams); $encodedMessage = $this->messageEncoder->encode($topicName, $entityParams); $serializedData = [ 'entity_id' => null, 'entity_link' => '', 'meta_information' => $encodedMessage, ]; $data = [ 'data' => [ OperationInterface::BULK_ID => $groupId, OperationInterface::TOPIC_NAME => $topicName, OperationInterface::SERIALIZED_DATA => $this->jsonSerializer->serialize($serializedData), OperationInterface::STATUS => OperationInterface::STATUS_TYPE_OPEN, ], ]; /** @var \Magento\AsynchronousOperations\Api\Data\OperationInterface $operation */ $operation = $this->operationFactory->create($data); return $this->entityManager->save($operation); } }