Skip to content

Commit

Permalink
Publish 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Sykes, Ben (GE Digital) committed Nov 13, 2017
0 parents commit 0162252
Show file tree
Hide file tree
Showing 22 changed files with 3,759 additions and 0 deletions.
1 change: 1 addition & 0 deletions .cfignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
36 changes: 36 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"extends": "standard",
"env": {
"es6": true,
"node": true,
"mocha": true
},
"plugins":[
],
"rules": {
"array-bracket-spacing": [2, "never"],
"camelcase": [0, { "properties": "always" }],
"computed-property-spacing": [2, "never"],
"generator-star-spacing": [2, { "before": false, "after": true }],
"indent": [2, 2, { "SwitchCase": 1 }],
"max-len": [2, 150, 4, { "ignoreUrls": true, "ignorePattern": "\t*.*\\(\\'\\.?\/\\w.*\\'\\).*"}],
"no-duplicate-imports": 2,
"no-whitespace-before-property": 2,
"object-curly-spacing": [2, "always"],
"prefer-arrow-callback": 2,
"prefer-rest-params": 2,
"quote-props": [2, "as-needed", { "keywords": true }],
"semi": [2, "always"],
"space-before-function-paren": [2, { "anonymous": "always", "named": "never" }],
"template-curly-spacing": [2, "never"],
"yield-star-spacing": [2, { "before": false, "after": true }],
"require-jsdoc": ["error", {
"require": {
"FunctionDeclaration": true,
"MethodDefinition": true,
"ClassDeclaration": true
}
}],
"valid-jsdoc": [2, {"requireParamDescription": false, "requireReturn": false}]
}
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
manifest.yml
64 changes: 64 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
###GE Software Development License Agreement – General Release

THIS SOFTWARE LICENSE AGREEMENT (the “License”) describes the rights granted by the General Electric Company, operating through GE Digital (also referred to as “GE Software”), located at 2623 Camino Ramon, San Ramon, CA 94583 (herein referred to as “Licensor”) to any entity (the “Licensee”) receiving a copy of any of the following GE Digital development materials: Predix DevBox; Predix Reference Application (“RefApp”); Predix Dashboard Seed; Predix Px, Predix Security Service redistributable .jar files; Predix Machine redistributable .jar files; and Predix Machine SDK . These materials may include scripts, compiled code, supporting components, and documentation and are collectively referred to as the “Licensed Programs”. Both Licensor and Licensee are referred to hereinafter as a “Party” and collectively as the “Parties” to this License

### Section 1 – Conditional Grant.
No Licensee is required to accept this License for use of the Licensed Programs. In the absence of a signed license agreement between Licensor and Licensee specifying alternate terms, any use of the Licensed Programs by the Licensee shall be considered acceptance of these terms. The Licensed Programs are copyrighted and are licensed, not sold, to you. If you are not willing to be bound by the terms of this License, do not install, copy or use the Licensed Programs. If you received this software from any source other than the Licensor, your access to the Licensed Programs is NOT permitted under this License, and you must delete the software and any copies from your systems.

###Section 2 – Warranty Disclaimer.
NO WARRANTIES. LICENSOR AND OUR AFFILIATES, RESELLERS, DISTRIBUTORS, AND VENDORS, MAKE NO WARRANTIES, EXPRESS OR IMPLIED, GUARANTEES OR CONDITIONS WITH RESPECT TO USE OF THE LICENSED PROGRAMS. LICENSEE’S USE OF ALL SUCH PROGRAMS ARE AT LICENSEE’S AND CUSTOMERS’ OWN RISK. LICENSOR PROVIDES THE LICENSED PROGRAMS ON AN “AS IS” BASIS “WITH ALL FAULTS” AND “AS AVAILABLE.” LICENSOR DOES NOT GUARANTEE THE ACCURACY OR TIMELINESS OF INFORMATION AVAILABLE FROM, OR PROCESSED BY, THE LICENSED PROGRAMS. TO THE EXTENT PERMITTED UNDER LAW, LICENSOR EXCLUDES ANY IMPLIED WARRANTIES, INCLUDING FOR MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A PARTICULAR PURPOSE, WORKMANLIKE EFFORT, AND NON-INFRINGEMENT. NO GUARANTEE OF UNINTERRUPTED, TIMELY, SECURE, OR ERROR-FREE OPERATION IS MADE.

THESE LICENSED PROGRAMS MAY BE USED AS PART OF A DEVELOPMENT ENVIRONMENT, AND MAY BE COMBINED WITH OTHER CODE BY END-USERS. LICENSOR IS NOT ABLE TO GUARANTEE THAT THE LICENSED PROGRAMS WILL OPERATE WITHOUT DEFECTS WHEN USED IN COMBINATION WITH END-USER SOFTWARE. LICENSEE IS ADVISED TO SAFEGUARD IMPORTANT DATA, TO USE CAUTION, AND NOT TO RELY IN ANY WAY ON THE CORRECT FUNCTIONING OR PERFORMANCE OF ANY COMBINATION OF END-USER SOFTWARE AND THE LICENSED PROGRAMS AND/OR ACCOMPANYING MATERIALS. LICENSEE IS ADVISED NOT TO USE ANY COMBINATION OF LICENSED PROGRAMS AND END-USER PROVIDED SOFTWARE IN A PRODUCTION ENVIRONMENT WITHOUT PRIOR SUITABILITY AND DEFECT TESTING.

###Section 3 – Feedback.
It is expressly understood, acknowledged and agreed that you may provide GE reasonable suggestions, comments and feedback regarding the Software, including but not limited to usability, bug reports and test results, with respect to Software testing (collectively, "Feedback"). If you provide such Feedback to GE, you shall grant GE the following worldwide, non-exclusive, perpetual, irrevocable, royalty free, fully paid up rights:

a. to make, use, copy, modify, sell, distribute, sub-license, and create derivative works of, the Feedback as part of any product, technology, service, specification or other documentation developed or offered by GE or any of its affiliates (individually and collectively, "GE Products");
b. to publicly perform or display, import, broadcast, transmit, distribute, license, offer to sell, and sell, rent, lease or lend copies of the Feedback (and derivative works thereof) as part of any GE Product;
c. solely with respect to Licensee's copyright and trade secret rights, to sublicense to third parties the foregoing rights, including the right to sublicense to further third parties; and
d. to sublicense to third parties any claims of any patents owned or licensable by Licensee that are necessarily infringed by a third party product, technology or service that uses, interfaces, interoperates or communicates with the Feedback or portion thereof incorporated into a GE Product, technology or service. Further, you represent and warrant that your Feedback is not subject to any license terms that would purport to require GE to comply with any additional obligations with respect to any GE Products that incorporate any Feedback.

###Section 4 – Reserved

###Section 5 – Limitation of Liability.
LIABILITY ARISING UNDER THIS LICENSE, WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), SHALL BE LIMITED TO DIRECT, OBJECTIVELY MEASURABLE DAMAGES. LICENSOR SHALL HAVE NO LIABILITY TO THE OTHER PARTY OR TO ANY THIRD PARTY, FOR ANY INCIDENTAL, PUNITIVE, INDIRECT, OR CONSEQUENTIAL DAMAGES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. LIABILITY FOR ANY SOFTWARE LICENSED FROM THIRD PARTIES FOR USE WITH THE SERVICES IS EXPLICILTLY DISCLAIMED AND LIMITED TO THE MAXIMUM EXTENT PERMITTED BY LAW.

Notwithstanding anything to the contrary, the aggregate liability of Licensor and its suppliers under this License shall not exceed the total amounts paid by Licensee to Licensor hereunder during the one-year period immediately preceding the event which gave rise to the claims.

###Section 6 – License.

A. License Grant. Subject to the terms and conditions of this License, Licensor hereby grants Licensee a worldwide, perpetual, royalty-free, non-exclusive license to:

1. install the Licensed Programs on Licensee’s premises, and permit Licensee’s users to use the Licensed Programs so installed, solely for Licensee’s own development, testing, demonstration, staging, and production of Licensee’s own software that makes use of the Licensed Programs in a way that adds substantial functionality not present in the Licensed Programs (the result, a “Licensee Application”);

2. permit Licensee to permit third-party hosts (“Hosts”) to install the Licensee Application on such Hosts’ respective premises on Licensee’s behalf, and permit Licensee’s users to access and use the Licensed Programs so installed, solely for Licensee’s own development, testing, demonstration, staging and production purposes

3. install the Licensee Application on Licensee’s own premises and permit its own users to use the Licensee Application so installed on the same terms as sub-sections (i) and (ii) above.

B. For the purposes of this License, the right to “use” the Licensed Programs shall include the right to utilize, run, access, store, copy, test or display the Licensed Programs. No right or license is granted or agreed to be granted to disassemble or decompile any Licensed Programs furnished in object code form, and Licensee agrees not to engage in any such conduct unless permitted by law. Reverse engineering of Licensed Programs provided in object code form is prohibited, unless such a right is explicitly granted by any explicit license subject to sub-section (d) below or as a matter of law, and then only to the extent explicitly permitted. Licensor shall have no obligation to support any such reverse engineering, any product or derivative of such reverse engineering, or any use of the Licensed Programs with any modified versions of any of their components under this License.

C. Licensee shall ensure that any Licensee Applications incorporate the Licensed Programs in such a way as to prevent third parties (other than Hosts) from viewing the code of the Licensed Programs or gaining access to any programmatic interface or other hidden aspect of the Licensed Programs. Licensee shall also restrict distribution of the Licensed Programs, including as part of Licensee Applications, to only those parties who are notified of, and subject to, an enforceable obligation to refrain from any of the prohibited activities listed herein, such as reverse engineering or disassembling the Licensed Programs.


D. Use of some open source and third party software applications or components included in or accessed through the Licensed Programs may be subject to other terms and conditions found in a separate license agreement, terms of use or “Notice” file located at the download page. The Licensed Programs are accompanied by additional software components solely to enable the Licensed Programs to operate as designed. Licensee is not permitted to use such additional software independently of the Licensed Programs unless Licensee secures a separate license for use from the named vendor. Do not use any third party code unless you agree with the applicable license terms for that code.

E. Title. Title to and ownership of the Licensed Programs shall at all times remain with Licensor.

###Section 7 – Termination.

A) The Licensor reserves the right to cease distribution and grant of further licenses to any or all of the Licensed Programs at any time in its sole discretion.

B) The Licensor reserves the right to at any time and at its sole discretion provide updated versions of any or all of the Licensed Programs that supercede and replace the prior version of that Licensed Program.

C) Your license rights under Section 6 are effective until terminated as described below:

i) This license and all rights under it will terminate or cease to be effective without notice if Licensee breaches the terms of the License and does not correct or remedy such breach promptly.

ii) Notwithstanding the foregoing, Licensee may terminate this License at any time for any reason or no reason by providing the Licensor written notice thereof.

D) Upon any expiration or termination of this License, the rights and licenses granted to you under this License shall immediately terminate, and you shall immediately cease using and delete the Licensed Programs. Licensee Applications based upon the Licensed Programs (see Section 6(a) above) are not subject to this limitation.

In the event of any expiration or termination of this Licensee, any Confidentiality provision, disclaimers of GE’s representations and warranties, choice of applicable law and limitations of GE’s liability shall survive.

###Section 8 – Applicable Law.
The License shall be governed by and interpreted in accordance with the substantive law of the State of California, U.S.A., excluding its conflicts of law provisions, and by the courts of that state.
Binary file added OSS_NOTICE.pdf
Binary file not shown.
104 changes: 104 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# predix-eventhub-client
Node module to interact with Predix Event Hub supporting publish/subscribe.
For more information on Predix Event Hub, [see documentation here](https://docs.predix.io/en-US/content/service/data_management/event_hub/).

## Installation

`npm install --save predix-eventhub-client`

## Subscriber
To subscribe to an Event Hub stream, create an instance of Subscriber. e.g.

```
const Subscriber = require('predix-eventhub-client').Subscriber;
const options = {
uri: 'event-hub-aws-usw02.data-services.predix.io:443',
zoneId: '<YOUR EVENT HUB ZONE ID>',
uaaUrl: 'https://<YOUR_UAA_URL>/oauth/token',
clientId: '<YOUR UAA CLIENT>',
clientSecret: '<YOUR UAA SECRET>',
subscriberName: 'SUB-123'
};
const sub = new Subscriber(options);
console.log('Subscribing...');
sub.registerCallback((err, body, data) => {
if (err) {
console.log('Got Error', err);
return;
}
console.log('Got Message:', body, 'tags:', data.tags);
});
```

> NOTE: `subscriberName` is used to determine the different between subscribers. Subscribers using the same name will have their messages load-balanced between instances.
## Publisher
To publish to an Event Hub stream, create an instance of Publisher. e.g:

```
const Publisher = require('predix-eventhub-client').Publisher;
const options = {
uri: 'event-hub-aws-usw02.data-services.predix.io:443',
zoneId: '<YOUR EVENT HUB ZONE ID>',
uaaUrl: 'https://<YOUR_UAA_URL>/oauth/token',
clientId: '<YOUR UAA CLIENT>',
clientSecret: '<YOUR UAA SECRET>'
};
const pub = new Publisher(options);
let c = 0;
setInterval(() => {
const tags = {
count: c++
};
pub.postEvent('Hello, Event Hub', tags);
}, 1000);
```

> NOTE: Tags are optional, but the values *will* be converted into a String. Only string values are allowed in the tags object.
## Pub/Sub
If both publish and subscribe are needed, there is a convenience wrapper class, `EHClient`. e.g.

```
const EHClient = require('predix-eventhub-client').EHClient;
const options = {
// Load the Event Hub details from VCAP_SERVICES for me!
vcapServiceName: process.env.EVENT_HUB_SERVICE_NAME,
uaaUrl: process.env.UAA_URL,
clientId: process.env.UAA_CLIENT_ID,
clientSecret: process.env.UAA_CLIENT_SECRET
};
const client = new EHClient(options);
const pub = client.Publisher;
const sub = client.Subscriber;
let c = 0;
setInterval(() => {
pub.postEvent('Hello, Event Hub', { count: `${c++}` });
}, 1000);
sub.registerCallback((err, body, data) => {
if (err) {
console.log('Got Error', err);
return;
}
console.log('Got Message:', body, 'tags:', data.tags);
});
```

> NOTE: In this example we have the Event Hub connection details being provided from the Cloud Foundry VCAP_SERVICES environment variable. To use this feature, set the `vcapServiceName` option to the name of the bound service.
See examples in the [example](example) folder
144 changes: 144 additions & 0 deletions eventhub.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
syntax = "proto3";
option java_multiple_files = true;
option java_package = "com.ge.predix.eventhub";
option java_outer_classname = "EventHubService";
package predix.eventhub;


// A Timestamp represents a point in time independent of any time zone
// or calendar, represented as seconds and fractions of seconds at
// nanosecond resolution in UTC Epoch time. It is encoded using the
// Proleptic Gregorian Calendar which extends the Gregorian calendar
// backwards to year one. It is encoded assuming all minutes are 60
// seconds long, i.e. leap seconds are "smeared" so that no leap second
// table is needed for interpretation. Range is from
// 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z.
// By restricting to that range, we ensure that we can convert to
// and from RFC 3339 date strings.
// See [https://www.ietf.org/rfc/rfc3339.txt](https://www.ietf.org/rfc/rfc3339.txt).
//
// Example 1: Compute Timestamp from POSIX `time()`.
//
// Timestamp timestamp;
// timestamp.set_seconds(time(NULL));
// timestamp.set_nanos(0);
//
// Example 2: Compute Timestamp from POSIX `gettimeofday()`.
//
// struct timeval tv;
// gettimeofday(&tv, NULL);
//
// Timestamp timestamp;
// timestamp.set_seconds(tv.tv_sec);
// timestamp.set_nanos(tv.tv_usec * 1000);
//
// Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`.
//
// FILETIME ft;
// GetSystemTimeAsFileTime(&ft);
// UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
//
// // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z
// // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z.
// Timestamp timestamp;
// timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL));
// timestamp.set_nanos((INT32) ((ticks % 10000000) * 100));
//
// Example 4: Compute Timestamp from Java `System.currentTimeMillis()`.
//
// long millis = System.currentTimeMillis();
//
// Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)
// .setNanos((int) ((millis % 1000) * 1000000)).build();
//
//
// Example 5: Compute Timestamp from current time in Python.
//
// now = time.time()
// seconds = int(now)
// nanos = int((now - seconds) * 10**9)
// timestamp = Timestamp(seconds=seconds, nanos=nanos)
//
//

message Timestamp {

// Represents seconds of UTC time since Unix epoch
// 1970-01-01T00:00:00Z. Must be from from 0001-01-01T00:00:00Z to
// 9999-12-31T23:59:59Z inclusive.
int64 seconds = 1;

// Non-negative fractions of a second at nanosecond resolution. Negative
// second values with fractions must still have non-negative nanos values
// that count forward in time. Must be from 0 to 999,999,999
// inclusive.
int32 nanos = 2;
}

message Message {
string id = 1; // Message ID - UUID
bytes body = 2; // Payload from the Producer. there is also "Any" type, but its still under development
string zone_id = 3;
map<string, string> tags = 4; // Some general attributes, could potentially be used for tagging and others
bytes key = 5;
string topic = 6 ;
int32 partition = 7 ;
int64 offset = 8 ;
Timestamp timestamp = 9 ;
}

message Ack {
string id = 1;
AckStatus status_code = 2;
string desc = 3;
string topic = 4 ; // this you will only get this the ack is a success
int32 partition = 5 ; // this you will only get this the ack is a success
int64 offset = 6 ; // this you will only get this the ack is a success
Timestamp timestamp = 7 ; // this you will only get this the ack is a success
bytes body = 8 ; // you will only get this if the ack is a failure .
string zone_id = 9; // you will only get this if the ack is a failure .
map<string, string> tags = 10; // you will only get this if the ack is a failure .
bytes key = 11; // you will only get this if the ack is a failure .
}

enum AckStatus {
ACCEPTED = 0;
BAD_REQUEST = 1;
REQUEST_TOO_LARGE = 2;
FAILED = 3;
}

message Messages {
repeated Message msg = 1;
}

message PublishRequest {
Messages messages = 1;
}

message PublishResponse {
repeated Ack ack = 1;
}

message SubscriptionResponse {
repeated Ack ack = 1 ;
}

message SubscriptionRequest {
string zone_id = 1; // zone name, this will be the user's zone
string subscriber = 2; // subscriber name, this will be utilized to parallelize processing
string instance_id = 3; // particular instance of the subscriber
}

// Publisher service definition
service Publisher {
// Send message to topic. Topic name will be in URI
rpc send (stream PublishRequest) returns (stream PublishResponse) {}
}

// Subscriber service definition
service Subscriber {
// Receive message from a topic, as a subscriber
rpc receive (SubscriptionRequest) returns (stream Message) {}
rpc receiveWithAcks (stream SubscriptionResponse) returns (stream Message) {}
}
1 change: 1 addition & 0 deletions example/cfpubsub/.cfignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
1 change: 1 addition & 0 deletions example/cfpubsub/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!manifest.yml

0 comments on commit 0162252

Please sign in to comment.