Skip to content

Commit

Permalink
[service-bus] Fixing some issues with the samples (#9412)
Browse files Browse the repository at this point in the history
- Needed to add in AsyncIterable
- `useProxy.ts` was incorrectly loading ws, causing it to not actually use a proxy.
- `useProxy.ts` wasn't compiling against later versions of https-proxy-agent
  • Loading branch information
richardpark-msft authored Jun 9, 2020
1 parent fc3fa40 commit 1c6d4fd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
17 changes: 11 additions & 6 deletions sdk/servicebus/service-bus/samples/javascript/useProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ require("dotenv").config();

// Define connection string for your Service Bus instance here
const connectionString = process.env.SERVICE_BUS_CONNECTION_STRING || "<connection string>";
const queueName = process.env.QUEUE_NAME || "<queue name>";

async function main() {
const proxyInfo = process.env.HTTP_PROXY || process.env.HTTPS_PROXY;
Expand All @@ -36,14 +37,18 @@ async function main() {
// No need to pass the `WebSocket` from "ws" package if you're in the browser
// in which case the `window.WebSocket` is used by the library.
webSocket: WebSocket,
webSocketConstructorOptions: { agent: proxyAgent }
}
webSocketConstructorOptions: { agent: proxyAgent },
},
});

const sender = sbClient.createSender(queueName);

console.log(`Sending message using proxy server ${proxyInfo}`);

await sender.send({
body: "sample message",
});

/*
Refer to other samples, and place your code here
to create queue clients, and to send/receive messages
*/
await sbClient.close();
}

Expand Down
20 changes: 13 additions & 7 deletions sdk/servicebus/service-bus/samples/typescript/src/useProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@

import { ServiceBusClient } from "@azure/service-bus";
import WebSocket from "ws";
import HttpsProxyAgent from "https-proxy-agent";
import { HttpsProxyAgent } from "https-proxy-agent";

// Load the .env file if it exists
import * as dotenv from "dotenv";
dotenv.config();

// Define connection string for your Service Bus instance here
const connectionString = process.env.SERVICE_BUS_CONNECTION_STRING || "<connection string>";
const queueName = process.env.QUEUE_NAME || "<queue name>";

export async function main() {
const proxyInfo = process.env.HTTP_PROXY || process.env.HTTPS_PROXY;

if (!proxyInfo) {
console.error(
"Error: Proxy information not provided, but it is required to run this sample. Exiting."
Expand All @@ -38,14 +40,18 @@ export async function main() {
// No need to pass the `WebSocket` from "ws" package if you're in the browser
// in which case the `window.WebSocket` is used by the library.
webSocket: WebSocket,
webSocketConstructorOptions: { agent: proxyAgent }
}
webSocketConstructorOptions: { agent: proxyAgent },
},
});

const sender = sbClient.createSender(queueName);

console.log(`Sending message using proxy server ${proxyInfo}`);

await sender.send({
body: "sample message",
});

/*
Refer to other samples, and place your code here
to create queue clients, and to send/receive messages
*/
await sbClient.close();
}

Expand Down
4 changes: 2 additions & 2 deletions sdk/servicebus/service-bus/samples/typescript/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"target": "ES2015",
"moduleResolution": "node",

"allowSyntheticDefaultImports": true,

"esModuleInterop": true,
"lib": ["ESNext.AsyncIterable"],
"outDir": "dist",
"rootDir": "src"
},
Expand Down

0 comments on commit 1c6d4fd

Please sign in to comment.