This package is abandoned and no longer maintained. No replacement package was suggested.

Message Queue Amazon SNS Transport (fork and improve from enqueue/sns)

Maintainers

👁 brightecapital

Package info

github.com/brighte-capital/sns

Homepage

pkg:composer/brightecapital/sns

Statistics

Installs: 12 073

Dependents: 0

Suggesters: 0

Stars: 0

1.0.2 2020-01-03 02:37 UTC

Requires

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 963f14c7fdad303ee7af207eb188ae4f1a46c25f

  • Ken Ngo <ken.ngo.woop@brighte.com.au>

queueamazonmessagingawsSNS

This package is auto-updated.

Last update: 2024-09-20 11:23:23 UTC


README

👁 Software license
👁 Version
👁 Download
👁 Build status
👁 Coverage

Description

This project was forked from enqueue/sns and made the following improvements:

  • Move all classes to src
  • Rename Tests to tests
  • Move examples to tests
  • Change namespace to Brighte\Sns

SnsProducer->send():

public function send(Destination $destination, Message $message): void
 {
 InvalidDestinationException::assertDestinationInstanceOf($destination, SnsDestination::class);
 InvalidMessageException::assertMessageInstanceOf($message, SnsMessage::class);

 $body = $message->getBody();
 if (empty($body)) {
 throw new InvalidMessageException('The message body must be a non-empty string.');
 }

 $topicArn = $this->context->getTopicArn($destination);

 $arguments = [
 'Message' => $message->getBody(),
 'TopicArn' => $topicArn,
 ];

 if ($message->getProperties()) {
 foreach ($message->getProperties() as $name => $value) {
 $arguments['MessageAttributes'][$name] = ['DataType' => 'String', 'StringValue' => $value];
 }
 }

 if ($message->getMessageAttributes()) {
 foreach ($message->getMessageAttributes() as $name => $value) {
 $arguments['MessageAttributes'][$name] = ['DataType' => 'String', 'StringValue' => $value];
 }
 }

 if (null !== ($structure = $message->getMessageStructure())) {
 $arguments['MessageStructure'] = $structure;
 }
 if (null !== ($phone = $message->getPhoneNumber())) {
 $arguments['PhoneNumber'] = $phone;
 }
 if (null !== ($subject = $message->getSubject())) {
 $arguments['Subject'] = $subject;
 }
 if (null !== ($targetArn = $message->getTargetArn())) {
 $arguments['TargetArn'] = $targetArn;
 }

 $result = $this->context->getSnsClient()->publish($arguments);

 if (false == $result->hasKey('MessageId')) {
 throw new \RuntimeException('Message was not sent');
 }

 $message->setSnsMessageId((string) $result->get('MessageId'));
 }