Skip to content
Open
Show file tree
Hide file tree
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
24 changes: 24 additions & 0 deletions carrera-sdk/consumer/php/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"description": "The CodeIgniter framework",
"name": "codeigniter/framework",
"type": "project",
"homepage": "https://codeigniter.com",
"license": "MIT",
"support": {
"forum": "http://forum.codeigniter.com/",
"wiki": "https://github.com/bcit-ci/CodeIgniter/wiki",
"slack": "https://codeigniterchat.slack.com",
"source": "https://github.com/bcit-ci/CodeIgniter"
},
"require": {
"php": ">=5.3.7",
"packaged/thrift": "^0.11.0"
},
"suggest": {
"paragonie/random_compat": "Provides better randomness in PHP 5.x"
},
"require-dev": {
"mikey179/vfsStream": "1.1.*",
"phpunit/phpunit": "4.* || 5.*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

$config['carrera'] = array(
// proxy list
'CARRERA_PROXY_LIST' => array('127.0.0.1:9713'),
// time out for each send from proxy to mq broker
'CARRERA_PROXY_TIMEOUT' => 50,
// time out for each send from client to proxy
'CARRERA_CLIENT_TIMEOUT' => 1000,
// log path
'CARRERA_CLIENT_LOGPATH' => '/home/xiaoju/webroot/log/mq/',
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

$config['carrera'] = array(
// proxy list
'CARRERA_PROXY_LIST' => array('127.0.0.1:9713'),
// time out for each send from proxy to mq broker
'CARRERA_PROXY_TIMEOUT' => 50,
// time out for each send from client to proxy
'CARRERA_CLIENT_TIMEOUT' => 1000,
// log path
'CARRERA_CLIENT_LOGPATH' => '/home/xiaoju/webroot/log/mq/',
);
38 changes: 38 additions & 0 deletions carrera-sdk/consumer/php/controllers/test/TestCarrera.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/**
* @property Carrera carrera
*/
class TestCarrera extends CI_Controller {

public function index() {
echo "Hello Carrera Consumer\n";
}

public function consume() {
$this->load->library('carrera/Carrera');
$ret = $this->carrera->pull('cg_1', 'Test');
if ($ret['code'] > 0) {
var_dump($ret);
return;
}
$context = $ret['ret']['context'];
$messages = $ret['ret']['messages'];
$aSuccessOffsets = [];
$aFailOffsets = [];
foreach ($messages as $message) {
if ($this->callback($message->value)) {
$aSuccessOffsets[] = $message->offset;
} else {
$aFailOffsets[] = $message->offset;
}
}
$ret = $this->carrera->submit($context, $aSuccessOffsets, $aFailOffsets);
var_dump($ret);
}

private function callback($value) {
echo "msg: ".$value."\r\n";
return (mt_rand(1,100) > 50);
}
}
Loading