Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Kinesis Firehose adapter and tests #42

Merged
merged 5 commits into from
Oct 25, 2017
Merged

Add Kinesis Firehose adapter and tests #42

merged 5 commits into from
Oct 25, 2017

Conversation

joemeehan
Copy link
Contributor

Adding an adapter to send messages to a Kinesis Firehose stream. This adapter only supports the enqueue function (as that's the only thing you can do to a Kinesis Firehose delivery stream).

@biggianteye
Copy link
Contributor

Consider using __FUNCTION__ in all the MethodNotSupportedException calls.

Copy link
Contributor

@h-bragg h-bragg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments and things to change.

{
array_walk($messages, function (MessageInterface &$message, $id) {
$metadata = $message->getMetadata();
$message = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this has id, body and attributes ala sqs instead of just body?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, I thought that the expected behaviour was to pass the body and metadata through in the message, but release now that's just a specific SQS thing. I've simplified this to just pass through the body as the top-level message.

* @param string $deliveryStreamName
* @param array $options
*/
public function __construct(FirehoseClient $client, $deliveryStreamName, array $options = [])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$options doesn't do anything.

public function enqueue(array $messages)
{
$failed = [];
$batches = array_chunk($this->createEnqueueEntries($messages), self::BATCHSIZE_SEND);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we probably don't do this currently. But we should allow this field to be overloaded.

an option in the constructor options, or argument or getter/setter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've add this as an option and added an options accessor method.

class FirehoseIntegrationTest extends TestCase
{
/** @var string */
private $queueName;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The property $queueName is not used and could be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


public function setUp()
{
$this->deliveryStreamName = 'delivery_stream_foo';
Copy link
Contributor

@h-bragg h-bragg Oct 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The property deliveryStreamName does not exist. Did you maybe forget to declare it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now declared

'Records' => $requestRecords,
];

$results = $this->client->putRecordBatch($request);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a top level failed result or does it always return a RequestResponses?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http://docs.aws.amazon.com/aws-sdk-php/v3/api/api-firehose-2015-08-04.html#putrecordbatch

There's always a RequestResponses key in the result object. There is also a FailedPutCount element at the top-level in the response, but to know which messages have failed we'll need to inspect the RequestResponses object anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am just thinking about what happens if the service is down, I assume guzzle would throw a ServerException on this call. As long as we are happy passing that back to the user, should be fine. Or we could try{}catch{} and wrap it in a FailedEnqueueException.

So the user of this can then just handle failed enqueue exceptions and re-queue happily.

@wpillar
Copy link
Contributor

wpillar commented Oct 6, 2017

Is kinesis firehose a queue?

@wpillar
Copy link
Contributor

wpillar commented Oct 6, 2017

The fact that we're having to implement AdapterInterface with mostly MethodNotSupported implementations should be a flag, no? It looks like we're using this abstraction to simply wrap FirehoseClient not because it's a useful abstraction?

Fair/unfair?

@joemeehan
Copy link
Contributor Author

I'd argue Firehose is a queue application, it's just that it handles consuming messages itself (into S3 or Redshift). In one of our other applications, we would be using it in a functionally equivalent way to the SqsAdapter (which is what we're doing at the moment) - having this alternative available would be useful.

Copy link
Contributor

@h-bragg h-bragg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@h-bragg h-bragg merged commit 3084e3f into master Oct 25, 2017
@h-bragg h-bragg deleted the kinesis-firehose branch October 25, 2017 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants