Skip to content

Commit

Permalink
Merge pull request #1007 from memphisdev/add-account-id-examples
Browse files Browse the repository at this point in the history
add account_id
  • Loading branch information
avrhamNeeman committed Jun 19, 2023
2 parents 8f5fbd8 + 262bfd9 commit 892bc1e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
21 changes: 19 additions & 2 deletions ui_src/src/components/sdkExsample/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import * as monaco from 'monaco-editor';

import { PROTOCOL_CODE_EXAMPLE, SDK_CODE_EXAMPLE, selectLngOption, selectProtocolLngOptions } from '../../const/codeExample';
import {
LOCAL_STORAGE_ACCOUNT_ID,
LOCAL_STORAGE_BROKER_HOST,
LOCAL_STORAGE_ENV,
LOCAL_STORAGE_REST_GW_HOST,
Expand Down Expand Up @@ -63,12 +64,14 @@ const SdkExample = ({ consumer, showTabs = true, stationName, username, connecti
localStorage.getItem(LOCAL_STORAGE_ENV) === 'docker'
? 'localhost'
: localStorage.getItem(LOCAL_STORAGE_BROKER_HOST)
? localStorage.getItem(LOCAL_STORAGE_BROKER_HOST)
: 'memphis.memphis.svc.cluster.local';
? localStorage.getItem(LOCAL_STORAGE_BROKER_HOST)
: 'memphis.memphis.svc.cluster.local';
codeEx.producer = codeEx.producer?.replaceAll('<memphis-host>', host);
codeEx.consumer = codeEx.consumer?.replaceAll('<memphis-host>', host);
codeEx.producer = codeEx.producer?.replaceAll('<station-name>', stationName);
codeEx.consumer = codeEx.consumer?.replaceAll('<station-name>', stationName);
codeEx.producer = codeEx.producer?.replaceAll('<account-id>', localStorage.getItem(LOCAL_STORAGE_ACCOUNT_ID));
codeEx.consumer = codeEx.consumer?.replaceAll('<account-id>', localStorage.getItem(LOCAL_STORAGE_ACCOUNT_ID));
if (username) {
codeEx.producer = codeEx.producer?.replaceAll('<application type username>', username);
codeEx.consumer = codeEx.consumer?.replaceAll('<application type username>', username);
Expand All @@ -86,6 +89,20 @@ const SdkExample = ({ consumer, showTabs = true, stationName, username, connecti
codeEx.consumer = codeEx.consumer?.replaceAll('connection_token', 'password');
codeEx.producer = codeEx.producer?.replaceAll('<broker-token>', '<password>');
codeEx.consumer = codeEx.consumer?.replaceAll('<broker-token>', '<password>');
} else {
const accountId = localStorage.getItem(LOCAL_STORAGE_ACCOUNT_ID)
const regexPatternGo = `, memphis\.AccountId\("${accountId}"\)`;
codeEx.producer = codeEx.producer?.replaceAll(regexPatternGo, "");
codeEx.consumer = codeEx.consumer?.replaceAll(regexPatternGo, "");
const regexPatternJs = `accountId: '${accountId}'`;
codeEx.producer = codeEx.producer?.replaceAll(regexPatternJs, "");
codeEx.consumer = codeEx.consumer?.replaceAll(regexPatternJs, "");
codeEx.producer = codeEx.producer?.replaceAll(regexPatternJs, "");
codeEx.consumer = codeEx.consumer?.replaceAll(regexPatternJs, "");

const regexPatternPython = `, account_id="${accountId}"`;
codeEx.producer = codeEx.producer?.replaceAll(regexPatternPython, "");
codeEx.consumer = codeEx.consumer?.replaceAll(regexPatternPython, "");
}
setCodeExample(codeEx);
}
Expand Down
20 changes: 12 additions & 8 deletions ui_src/src/const/codeExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export const SDK_CODE_EXAMPLE = {
memphisConnection = await memphis.connect({
host: '<memphis-host>',
username: '<application type username>',
connectionToken: '<broker-token>'
connectionToken: '<broker-token>',
accountId: '<account-id>'
});
const producer = await memphisConnection.producer({
Expand Down Expand Up @@ -55,7 +56,8 @@ export const SDK_CODE_EXAMPLE = {
memphisConnection = await memphis.connect({
host: '<memphis-host>',
username: '<application type username>',
connectionToken: '<broker-token>'
connectionToken: '<broker-token>',
accountId: '<account-id>'
});
const consumer = await memphisConnection.consumer({
Expand Down Expand Up @@ -99,7 +101,8 @@ export const SDK_CODE_EXAMPLE = {
memphisConnection = await memphis.connect({
host: '<memphis-host>',
username: '<application type username>',
connectionToken: '<broker-token>'
connectionToken: '<broker-token>',
accountId: '<account-id>'
});
const producer = await memphisConnection.producer({
Expand Down Expand Up @@ -130,7 +133,8 @@ export const SDK_CODE_EXAMPLE = {
memphisConnection = await memphis.connect({
host: '<memphis-host>',
username: '<application type username>',
connectionToken: '<broker-token>'
connectionToken: '<broker-token>',
accountId: '<account-id>'
});
const consumer = await memphisConnection.consumer({
Expand Down Expand Up @@ -169,7 +173,7 @@ import (
)
func main() {
conn, err := memphis.Connect("<memphis-host>", "<application type username>", memphis.ConnectionToken("<broker-token>"))
conn, err := memphis.Connect("<memphis-host>", "<application type username>", memphis.ConnectionToken("<broker-token>"), memphis.AccountId("<account-id>"))
if err != nil {
os.Exit(1)
}
Expand Down Expand Up @@ -204,7 +208,7 @@ import (
)
func main() {
conn, err := memphis.Connect("<memphis-host>", "<application type username>", memphis.ConnectionToken("<broker-token>"))
conn, err := memphis.Connect("<memphis-host>", "<application type username>", memphis.ConnectionToken("<broker-token>"), memphis.AccountId("<account-id>"))
if err != nil {
os.Exit(1)
}
Expand Down Expand Up @@ -254,7 +258,7 @@ from memphis import Memphis, Headers, MemphisError, MemphisConnectError, Memphis
async def main():
try:
memphis = Memphis()
await memphis.connect(host="<memphis-host>", username="<application type username>", connection_token="<broker-token>")
await memphis.connect(host="<memphis-host>", username="<application type username>", connection_token="<broker-token>", account_id="<account-id>")
producer = await memphis.producer(station_name="<station-name>", producer_name="<producer-name>") # you can send the message parameter as dict as well
headers = Headers()
Expand Down Expand Up @@ -289,7 +293,7 @@ async def main():
try:
memphis = Memphis()
await memphis.connect(host="<memphis-host>", username="<application type username>", connection_token="<broker-token>")
await memphis.connect(host="<memphis-host>", username="<application type username>", connection_token="<broker-token>", account_id="<account-id>")
consumer = await memphis.consumer(station_name="<station-name>", consumer_name="<consumer-name>", consumer_group="")
consumer.set_context({"key": "value"})
Expand Down

0 comments on commit 892bc1e

Please sign in to comment.