Skip to content

Commit 71ebf28

Browse files
authored
Set client ID in samples (#541)
1 parent 2d189a2 commit 71ebf28

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

Diff for: samples/browser/pub_sub_mqtt5/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ function createClient(provider: AWSCognitoCredentialsProvider) : mqtt5.Mqtt5Clie
7878
wsConfig
7979
)
8080

81+
builder.withConnectProperties({
82+
clientId: "test-" + Math.floor(Math.random() * 100000000)
83+
});
84+
8185
let client : mqtt5.Mqtt5Client = new mqtt5.Mqtt5Client(builder.build());
8286

8387
client.on('error', (error) => {

Diff for: samples/browser/react_sample/src/PubSub5.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ function createClient(provider: AWSCognitoCredentialsProvider) : mqtt5.Mqtt5Clie
7878
AWS_IOT_ENDPOINT,
7979
wsConfig
8080
)
81+
builder.withConnectProperties({
82+
clientId: "test-" + Math.floor(Math.random() * 100000000)
83+
});
8184

8285
let client : mqtt5.Mqtt5Client = new mqtt5.Mqtt5Client(builder.build());
8386

Diff for: samples/node/pub_sub_electron_node/Main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ function createClientConfig(isWebsocket: boolean): mqtt5.Mqtt5ClientConfig {
9494

9595
builder.withConnectProperties({
9696
keepAliveIntervalSeconds: 1200,
97-
clientId: "test-client"
97+
clientId: "test-client" + Math.floor(Math.random() * 100000000)
9898
});
9999

100100
return builder.build();

Diff for: samples/node/pub_sub_mqtt5/index.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,15 @@ yargs.command('*', false, (yargs: any) => {
3737
type: 'string',
3838
required: false
3939
})
40+
.option('client_id', {
41+
alias: 'C',
42+
description: 'Client ID for MQTT connection.',
43+
type: 'string',
44+
required: false
45+
})
4046
}, main).parse();
4147

42-
function creatClientConfig(args : any) : mqtt5.Mqtt5ClientConfig {
48+
function createClientConfig(args : any) : mqtt5.Mqtt5ClientConfig {
4349
let builder : iot.AwsIotMqtt5ClientConfigBuilder | undefined = undefined;
4450

4551
if (args.key && args.cert) {
@@ -61,7 +67,9 @@ function creatClientConfig(args : any) : mqtt5.Mqtt5ClientConfig {
6167
);
6268
}
6369

70+
6471
builder.withConnectProperties({
72+
clientId: args.client_id || "test-" + Math.floor(Math.random() * 100000000),
6573
keepAliveIntervalSeconds: 1200
6674
});
6775

@@ -70,7 +78,7 @@ function creatClientConfig(args : any) : mqtt5.Mqtt5ClientConfig {
7078

7179
function createClient(args: any) : mqtt5.Mqtt5Client {
7280

73-
let config : mqtt5.Mqtt5ClientConfig = creatClientConfig(args);
81+
let config : mqtt5.Mqtt5ClientConfig = createClientConfig(args);
7482

7583
console.log("Creating client for " + config.hostName);
7684
let client : mqtt5.Mqtt5Client = new mqtt5.Mqtt5Client(config);

0 commit comments

Comments
 (0)