Skip to content

Commit 179b1e7

Browse files
authored
chore: update to fluvio 0.11.11 (#142)
1 parent 1e20dd1 commit 179b1e7

File tree

155 files changed

+16121
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+16121
-1
lines changed

docusaurus.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type * as Preset from "@docusaurus/preset-classic";
66

77
const FLUVIO_REPOSITORY_URL = "https://github.com/InfinyOn/fluvio";
88

9-
const STABLE_VERSION = "0.11.10";
9+
const STABLE_VERSION = "0.11.11";
1010

1111
const config: Config = {
1212
title: "Fluvio",
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"label": "NodeJS SDK",
3+
"position": 40
4+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
title: Examples
3+
sidebar_position: 20
4+
---
5+
6+
# NodeJS SDK Examples
7+
8+
* This client uses [`node-bindgen`] to wrap the Rust client.
9+
* It supports most administrator features.
10+
* The blocking calls to Fluvio return promises allowing for async on blocking Fluvio calls.
11+
* The [`PartitionConsumer.createStream`] call returns an [`asyncIterator`] to allow iterating over the stream in a for-loop.
12+
13+
To see the full docs, visit [our typedoc page].
14+
15+
[`node-bindgen`]: https://github.com/infinyon/node-bindgen
16+
[our typedoc page]: https://infinyon.github.io/fluvio-client-node/
17+
[`PartitionConsumer.createStream`]: https://infinyon.github.io/fluvio-client-node/classes/PartitionConsumer.html#createStream
18+
[`asyncIterator`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of
19+
20+
21+
## Example Workflow
22+
23+
Follow the [installation instructions](/) to run this example.
24+
25+
```js
26+
/**
27+
* This is an example of a basic Fluvio workflow in Typescript
28+
*
29+
* 1. Establish a connection to the Fluvio cluster
30+
* 2. Create a topic to store data in
31+
* 3. Create a producer and send some bytes
32+
* 4. Create a consumer, and stream the data back
33+
*/
34+
import Fluvio, { Offset, Record } from "@fluvio/client";
35+
36+
const TOPIC_NAME = "hello-node";
37+
const PARTITION = 0;
38+
39+
async function createTopic() {
40+
try {
41+
// Connect to the Fluvio cluster
42+
console.log("Connecting client to fluvio");
43+
await fluvio.connect();
44+
45+
// Create admin client;
46+
const admin = await fluvio.admin();
47+
48+
// Create topic
49+
console.log("Creating topic");
50+
await admin.createTopic(TOPIC_NAME);
51+
} catch (ex) {
52+
console.log("Topic already exists", ex);
53+
}
54+
}
55+
56+
const produce = async () => {
57+
// Connect to the Fluvio cluster
58+
console.log("Connecting client to fluvio");
59+
await fluvio.connect();
60+
61+
// Create a topic producer;
62+
const producer = await fluvio.topicProducer(TOPIC_NAME);
63+
await producer.send("example-key", "Hello World! - Time is " + Date());
64+
};
65+
66+
const consume = async () => {
67+
try {
68+
// Connect to the fluvio cluster referenced in the cli profile.
69+
await fluvio.connect();
70+
71+
// Create partition consumer
72+
const consumer = await fluvio.partitionConsumer(TOPIC_NAME, PARTITION);
73+
74+
console.log("read from the end");
75+
await consumer.stream(Offset.FromEnd(), async (record: Record) => {
76+
// handle record;
77+
console.log(`Key=${record.keyString()}, Value=${record.valueString()}`);
78+
process.exit(0);
79+
});
80+
} catch (ex) {
81+
console.log("error", ex);
82+
}
83+
};
84+
85+
// Create Fluvio Client Instance
86+
const fluvio = new Fluvio();
87+
createTopic();
88+
produce();
89+
consume();
90+
```
91+
92+
### Run
93+
94+
```shell
95+
$ npx ts-node example.ts
96+
```
97+
98+
## Links to Docs:
99+
- [Connect to Fluvio](https://infinyon.github.io/fluvio-client-node/interfaces/FluvioClient.html#connect)
100+
- [Create a Producer](https://infinyon.github.io/fluvio-client-node/interfaces/FluvioClient.html#topicProducer)
101+
- [Send to Topic](https://infinyon.github.io/fluvio-client-node/classes/TopicProducer.html#send)
102+
- [Get a Consumer](https://infinyon.github.io/fluvio-client-node/interfaces/FluvioClient.html#partitionConsumer)
103+
- [Create a Stream](https://infinyon.github.io/fluvio-client-node/classes/PartitionConsumer.html#createStream)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
title: Installation
3+
sidebar_position: 10
4+
---
5+
6+
## NodeJS SDK Installation Guide
7+
8+
Install [Node.js](https://nodejs.org/en/) (v**16.11.0** or above)
9+
10+
We are using [`npm`](https://nodejs.dev/en/learn/an-introduction-to-the-npm-package-manager/) as package manager.
11+
12+
## Create New Node project for Fluvio development
13+
14+
Run the following commands to set up your project for development:
15+
16+
```bash
17+
mkdir fluvio-demo && cd fluvio-demo
18+
npm init -y
19+
npm install -D typescript ts-node @types/node
20+
npm install -S @fluvio/client
21+
```
22+
23+
And your `package.json` should look similar to the following:
24+
25+
```json
26+
{
27+
"name": "fluvio-demo",
28+
"version": "1.0.0",
29+
"description": "",
30+
"main": "index.js",
31+
"scripts": {
32+
"test": "echo \"Error: no test specified\" && exit 1"
33+
},
34+
"keywords": [],
35+
"author": "",
36+
"license": "ISC",
37+
"devDependencies": {
38+
"@types/node": "^20.2.5",
39+
"ts-node": "^10.8.1",
40+
"typescript": "^5.3.3"
41+
},
42+
"dependencies": {
43+
"@fluvio/client": "^0.14.6"
44+
}
45+
}
46+
```
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"label": "Python SDK",
3+
"position": 30
4+
}
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
---
2+
title: Examples
3+
sidebar_position: 20
4+
---
5+
6+
# Python SDK Examples
7+
8+
* The Python client [wraps the rust client](https://www.infinyon.com/blog/2021/03/python-client/).
9+
* It currently does not support the administrator features that the rust client does.
10+
* The [PartitionConsumer.stream](https://infinyon.github.io/fluvio-client-python/fluvio.html#PartitionConsumer.stream) returns an object which implements the [python iterator convention](https://wiki.python.org/moin/Iterator) to allow for iterating over the stream in a for-loop.
11+
12+
To see the full docs, visit our [pdoc page](https://infinyon.github.io/fluvio-client-python/fluvio.html).
13+
## Example Workflow
14+
15+
Follow the [installation instructions](/) to run this example.
16+
17+
### Prerequisites
18+
19+
Create the topic used to produce and consume records:
20+
21+
```bash
22+
fluvio topic create python-data
23+
```
24+
25+
### Login
26+
27+
Login to Infinyon Cloud using username/password
28+
29+
```python
30+
from fluvio import cloud
31+
cloud.login(email="my@email.com", password="mypassword")
32+
```
33+
34+
You can also use the oauth method to log in. However this is only for interactive sessions.
35+
36+
```python
37+
from fluvio import cloud
38+
cloud.login(Oauth2=true)
39+
```
40+
41+
### Producer
42+
43+
Create a file called `python-produce.py`:
44+
45+
```python
46+
#!/usr/bin/env python
47+
from datetime import datetime
48+
from fluvio import Fluvio
49+
50+
TOPIC_NAME = "python-data"
51+
PARTITION = 0
52+
53+
if __name__ == "__main__":
54+
# Connect to cluster
55+
fluvio = Fluvio.connect()
56+
57+
# Produce 10 records to topic
58+
producer = fluvio.topic_producer(TOPIC_NAME)
59+
for x in range(10):
60+
producer.send_string("{}: timestamp: {}".format(x, datetime.now()))
61+
62+
# Flush the last entry
63+
producer.flush()
64+
```
65+
66+
Let's run the file:
67+
68+
```shell copy="fl"
69+
$ python python-produce.py
70+
```
71+
72+
### Consumer
73+
74+
Create a file called `python-consume.py`:
75+
76+
```python
77+
#!/usr/bin/env python
78+
from fluvio import Fluvio, Offset
79+
80+
TOPIC_NAME = "python-data"
81+
PARTITION = 0
82+
83+
if __name__ == "__main__":
84+
# Connect to cluster
85+
fluvio = Fluvio.connect()
86+
87+
# Consume last 10 records from topic
88+
consumer = fluvio.partition_consumer(TOPIC_NAME, PARTITION)
89+
for idx, record in enumerate( consumer.stream(Offset.from_end(10)) ):
90+
print("{}".format(record.value_string()))
91+
92+
if idx >= 9:
93+
break
94+
```
95+
96+
Let's run the file:
97+
98+
```shell copy="fl"
99+
$ python python-consume.py
100+
```
101+
102+
## Limitations
103+
* Fluvio cluster administration is not supported.
104+
* Python [async](https://docs.python.org/3/library/asyncio.html) is not supported.
105+
106+
## Example with a SmartModule
107+
108+
```python
109+
#!/usr/bin/env python
110+
import os
111+
from datetime import datetime
112+
from fluvio import Fluvio, Offset, ConsumerCoonfig
113+
114+
TOPIC_NAME = "hello-python-smartmodule"
115+
PARTITION = 0
116+
117+
# This is an example of a basic Fluvio workflow in Python
118+
#
119+
# 1. Create a topic to store data in via CLI
120+
# 2. Establish a connection to the Fluvio cluster
121+
# 3. Create a producer and send some bytes
122+
# 4. Create a consumer, and stream the data back
123+
if __name__ == "__main__":
124+
# Currently the Python client does not support creating topics
125+
# Using the fluvio CLI
126+
os.popen("fluvio topic create {}".format(TOPIC_NAME))
127+
128+
# Connect to cluster
129+
fluvio = Fluvio.connect()
130+
131+
# Produce to topic
132+
producer = fluvio.topic_producer(TOPIC_NAME)
133+
producer.send_string("Hello World! - Time is: {}".format(datetime.now()))
134+
135+
# Consume from topic
136+
# We're just going to get the last record
137+
consumer = fluvio.partition_consumer(TOPIC_NAME, PARTITION)
138+
139+
140+
# Create a ConsumerConfig using your "uppercase-map" smartmodule
141+
config = ConsumerConfig()
142+
config.smartmodule(name="uppercase-map")
143+
144+
for record in consumer.stream_with_config(Offset.from_end(0), config):
145+
print("{}".format(record.value_string()))
146+
break
147+
```
148+
149+
## Links to Docs:
150+
* [Connect to Fluvio](https://infinyon.github.io/fluvio-client-python/fluvio.html#Fluvio.connect)
151+
* [Get a Producer](https://infinyon.github.io/fluvio-client-python/fluvio.html#Fluvio.topic_producer)
152+
* [Send to Topic](https://infinyon.github.io/fluvio-client-python/fluvio.html#TopicProducer.send)
153+
* [Get a Consumer](https://infinyon.github.io/fluvio-client-python/fluvio.html#Fluvio.partition_consumer)
154+
* [Get a Stream](https://infinyon.github.io/fluvio-client-python/fluvio.html#PartitionConsumer.stream)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: Installation
3+
sidebar_position: 10
4+
---
5+
6+
## Python SDK Installation Guide
7+
8+
## Minimum Python
9+
10+
The minimum Python supported is 3.6.
11+
* https://wiki.python.org/moin/BeginnersGuide/Download
12+
13+
## Install Python's package manager `pip`
14+
You will need `pip` to install the `fluvio` package from PyPi
15+
* https://pip.pypa.io/en/stable/installation/
16+
17+
## Install [`fluvio`](https://pypi.org/project/fluvio/) with `pip`
18+
19+
Run the following to install [`fluvio`](https://pypi.org/project/fluvio/) package
20+
21+
```shell copy="fl"
22+
$ pip install fluvio
23+
```

0 commit comments

Comments
 (0)