public function batchPublish(array $messages) { $records = aray(); foreach ($messages as $message) { $records[] = array('Data' => $message['msgBody'], 'PartitionKey' => $message['routingKey']); } $result = $this->client->putRecords(array_merge(array('StreamName' => $this->streamName, 'Records' => $records), $this->getClientParams())); }
/** * {@inheritdoc} */ public function handleBatch(array $records) { $kinesisParameters = $this->getFormatter()->formatBatch($records); $kinesisParameters['StreamName'] = $this->streamName; try { /** @noinspection PhpUndefinedMethodInspection */ $this->kinesisClient->putRecords($kinesisParameters); } catch (\Exception $ex) { // As above, we intentionally allow logs to drop when Kinesis fails for any reason } return false === $this->bubble; }
public function testFactoryInitializesClient() { $client = KinesisClient::factory(array('key' => 'foo', 'secret' => 'bar', 'region' => 'us-east-1')); $this->assertInstanceOf('Aws\\Common\\Signature\\SignatureV4', $client->getSignature()); $this->assertInstanceOf('Aws\\Common\\Credentials\\Credentials', $client->getCredentials()); $this->assertEquals('https://kinesis.us-east-1.amazonaws.com', $client->getBaseUrl()); }
public function testTheGetShardIteratorOperationWorksViaMagicCall() { $client = KinesisClient::factory(array('key' => 'foo', 'secret' => 'bar', 'region' => 'us-east-1')); $client->addSubscriber(new MockPlugin(array(new Response(200, null, '{"ShardIterator":"foobar"}')))); $result = $client->getShardIterator(array('StreamName' => 'test', 'ShardId' => 'test', 'ShardIteratorType' => 'AT_SEQUENCE_NUMBER')); $this->assertEquals('foobar', $result['ShardIterator']); }
public function testFactory_001() { $dummy_kinesis = KinesisClient::factory(array('key' => 'XXXXXX', 'secret' => 'XXXXX', 'region' => Region::VIRGINIA)); $proxy1 = KinesisProxy::factory($dummy_kinesis, 'hoge'); $proxy2 = KinesisProxy::factory($dummy_kinesis, 'hoge'); $proxy3 = KinesisProxy::factory($dummy_kinesis, 'foo'); $this->assertTrue(spl_object_hash($proxy1) === spl_object_hash($proxy2)); $this->assertFalse(spl_object_hash($proxy1) === spl_object_hash($proxy3)); }
/** * Builds an iterator to start getting messages from the shard based on both injected config and the fact that * the store has a value for the last Sequence Number previously read */ protected function getInitialMessageIterator() { $start = null; if ($this->sequenceNumberStore) { $start = $this->sequenceNumberStore->fetch($this->streamName, $this->shardId); } $iteratorOptions = array('StreamName' => $this->streamName, 'ShardId' => $this->shardId); if ($start == null) { $iteratorOptions['ShardIteratorType'] = $this->defaultShardIteratorType; } else { $iteratorOptions['ShardIteratorType'] = 'AFTER_SEQUENCE_NUMBER'; $iteratorOptions['StartingSequenceNumber'] = $start; } return $this->client->getShardIterator($iteratorOptions)->get('ShardIterator'); }
/** * Send multiple events to Event bus * * Will submit all events in .2 seconds * * @param $event * @param $key * @param $object_name * @param $data * @return bool|\Guzzle\Service\Resource\Model */ public function sendMultiple($event, $key, $object_name, $data) { if ($this->client == null) { return false; } $records = []; foreach ($data as $record) { $event_data = ['id' => $this->id, 'event' => $event, 'reference_id' => strtolower($object_name) . '_' . $record[$object_name][$key], 'payload' => $record]; $records[] = ['Data' => SafeJson::encode($event_data), 'PartitionKey' => $record[$object_name][$key]]; } $time_start = microtime(true); $result = $this->client->putRecords(['Records' => $records, 'StreamName' => $this->streamName]); $time_end = microtime(true); $this->time_taken = number_format($time_end - $time_start, 2); return $result; }
<?php require 'vendor/autoload.php'; use Aws\Kinesis\KinesisClient; $client = KinesisClient::factory(array('region' => 'us-east-1')); $result = $client->putRecord(array('StreamName' => 'torqueData', 'Data' => json_encode($_GET), 'PartitionKey' => $_GET['session'])); require_once 'creds.php'; require_once 'auth_app.php'; // Create an array of all the existing fields in the database $result = $mysqli->query("SHOW COLUMNS FROM {$db_table}") or die("ERROR: {$mysqli->error}"); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $dbfields[] = $row['Field']; } } $result->close(); // Iterate over all the k* _GET arguments to check that a field exists if (sizeof($_GET) > 0) { $keys = array(); $values = array(); foreach ($_GET as $key => $value) { // Keep columns starting with k if (preg_match('/^k/', $key)) { $keys[] = $key; $values[] = $value; $submitval = 1; } elseif (in_array($key, array('v', 'eml', 'time', 'id', 'session', 'profile'))) { //else if (in_array($key, array("v", "eml", "time", "id", "session"))) { $keys[] = $key; $values[] = "'" . $value . "'"; $submitval = 1;
<?php require '../vendor/autoload.php'; use Aws\Kinesis\KinesisClient; use Aws\Common\Enum\Region; use Rf\Aws\Kinesis\ClientLibrary\KinesisProxy; define('STREAM_NAME', 'kinesis-trial'); $kinesis = KinesisClient::factory(array('key' => 'XXXXX', 'secret' => 'XXXXX', 'region' => Region::VIRGINIA)); $kinesis_proxy = KinesisProxy::factory($kinesis, STREAM_NAME); while (true) { $sample_data = date('YmdHis'); $kinesis_proxy->putRecord($sample_data, mt_rand(1, 1000000)); echo $sample_data, PHP_EOL; sleep(1); }