Skip to content
This repository was archived by the owner on Oct 12, 2023. It is now read-only.

Add support for Browsers & Web Sockets#29

Merged
AlexGhiondea merged 33 commits intoAzure:masterfrom
bterlson:new-msrest
Mar 18, 2019
Merged

Add support for Browsers & Web Sockets#29
AlexGhiondea merged 33 commits intoAzure:masterfrom
bterlson:new-msrest

Conversation

@bterlson
Copy link
Copy Markdown
Member

@bterlson bterlson commented Feb 15, 2019

This PR implements support for web sockets. This is required to enable AMQP support in the browser and to enable proxying support for Node.js.

amqp-common now uses the template build process. While I wouldn't expect this to be distributed separately from its dependencies (for now), this build process ensures the library can be built for the browser by dependents.

This works by adding some options to ConnectionContextBase#create:

  1. webSocket, a reference to a WebSocket constructor (e.g. WebSocket in the browser, or require('ws') in node. Proxy support is enabled by applying the proxy config to the WebSocket prior to passing it in to this API.
  2. webSocketEndpointPath, the path component to append after the host and port to reach the websocket endpoint, e.g. "$servicebus/websocket" for service bus.

Unfortunately, Rhea isn't super great in the browser - it depends on a number of very hefty node shims resulting in a fairly large bundle (~500KB). The most straight-forward way to enable this short-term is rollup-plugin-node-builtins but unfortunately NPM audit warns about this module. Another approach is to manually map node modules to browser dependencies.

Left to do:

  • Use API-Extractor to verify the external shape of the library hasn't changed with the updated dependencies.
  • Run tests in browser.
  • Browser-specific tests for web sockets
  • Node-specific tests for web sockets
  • Either remove rollup-plugin-node-builtins or find a way to silence the audit warnings in CI.

Future work:

  • Service Bus PR updating to this version of amqp-common.
  • Add tests for proxies (unclear presently how to do so using our CI infra, /cc @mikeharder)

Related to:

package.json Outdated
"is-buffer": "^2.0.3",
"jssha": "^2.3.1",
"ms-rest-azure": "^2.5.9",
"rhea": "^0.3.9",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember a comment about rhea being a peer dependency -- not sure if that is a relevant piece of information.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was rhea-promise.

Amar once mentioned that we shouldnt take a dependency on rhea directly and that we should use rhea-promise instead. I dont recall the reason why though...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the rhea version resolved in amqp-common doesnt match with that in rhea-promise, we might end up with 2 versions of rhea correct?

Wasnt this was the reason why rhea-promise is a peer dependency in amqp-common?
If so, then rhea should be a peer dependency as well.

package.json Outdated
"is-buffer": "^2.0.3",
"jssha": "^2.3.1",
"ms-rest-azure": "^2.5.9",
"rhea": "^0.3.9",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was rhea-promise.

Amar once mentioned that we shouldnt take a dependency on rhea directly and that we should use rhea-promise instead. I dont recall the reason why though...

package.json Outdated
"build": "npm run tslint && npm run tsc && cross-env rollup -c",
"test": "npm run build && npm run unit",
"unit": "nyc --reporter=lcov --reporter=text-lcov mocha -r ts-node/register -t 50000 ./tests/**/*.spec.ts",
"unit": "cross-env TS_NODE_COMPILER_OPTIONS=\"{\\\"module\\\":\\\"commonjs\\\"}\" nyc --reporter=lcov --reporter=text-lcov mocha -r ts-node/register -t 50000 ./tests/**/*.spec.ts",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could skip using ts-node altogether for running tests like we did in the service bus project

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can tackle this in a separate PR if we like?

@vaish1707
Copy link
Copy Markdown

@ramya-rao-a , @bterlson Does these changes also adds proxy for storage blob? We also connect to storage blob while establishing a connection to azure event hubs.
In addition to this, I also have these questions.
Currently I'm trying to reach azure event hub from our cloud foundry environment. All our outgoing Http calls for the application deployed in the Cloud foundry are done by supplying the proxy configuration(https://docs.run.pivotal.io/buildpacks/proxy-usage.html) to the rest client.
When it comes to AMQP which is azure event hubs, until your proxy changes gets merged for azure event hubs as well, what is other alternative which we can look for?

@bterlson
Copy link
Copy Markdown
Member Author

@vaish1707 I believe storage should already support proxies as that service uses HTTP rather than AMQP. I'm not sure if there are docs for supporting this though. @XiaoningLiu can you help @vaish1707 find docs for supporting proxies in the storage client?

Regarding support for proxies without this change landing, I wish I had a better answer. You could use the rhea library and talk AMQP directly to service bus, perhaps, but I think that would be a lot of work.

@vaish1707
Copy link
Copy Markdown

Thanks for the reply. @bterlson is there any tentative date on when amqp proxy support will be available for eventhubprocessorhost for nodejs client? Also while adding the http proxy to storage blob . Is it going to be to append to the storage blob end point?

@bterlson
Copy link
Copy Markdown
Member Author

The audit failure in CI is fixed by upgrading NYC in #31.

@bterlson
Copy link
Copy Markdown
Member Author

@vaish1707 sorry I can't commit to a date, I'm just not sure.

Proxy support for Storage should be a matter of replacing the underlying http agent with something like http-proxy-agent. You shouldn't need to change anything else other than how the client is configured initially.

import {
ApplicationTokenCredentials, DeviceTokenCredentials, UserTokenCredentials, MSITokenCredentials
} from "ms-rest-azure";
} from "@azure/ms-rest-nodeauth";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bterlson When you tested Service Bus by pointing the amqp-common dependency to your git branch, were you able to run any of the examples like interactiveLogin, servicePrincipalLogin or the test on auth without making any changes?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ramya-rao-a I didn't try the samples. I'll report here with my findings, though I may need your help getting the AD side set up properly.

@vaish1707
Copy link
Copy Markdown

@ramya-rao-a ,@bterlson until the proxy support is available for the eventprocessorhost . We tried an alternative solution to open up the firewall for the ports 5671 and 5672 over TCP . We are still facing issues evening after opening up those ports over TCP. Also for storage blob we have opened up 443 and 80 over TCP.Are we missing something here? Can you please help on this?

@AlexGhiondea
Copy link
Copy Markdown
Contributor

@vaish1707 would you mind opening a separate issue to discuss the issues you are running into? You can file an issue in the https://github.com/azure/azure-sdk-for-js repo and tag us in it!

@ramya-rao-a
Copy link
Copy Markdown
Contributor

@alexandrudima, https://github.com/Azure/azure-event-hubs-node/issues/210 was logged by @vaish1707

@vaish1707 Let's have this discussion in the original issue you logged, I'll try to loop in the Event Hubs service team to get their insight

@bterlson
Copy link
Copy Markdown
Member Author

Now rebased and ready to merge once tests pass. FWIW, the only diff between the current new-msrest commit and the non-rebased commit (b387a88) is the NYC change to package.json:

git diff new-msrest bterlson/new-msrest -- package.json
diff --git a/package.json b/package.json
index ea188c5..06ed70e 100644
--- a/package.json
+++ b/package.json
@@ -53,7 +53,7 @@
     "karma-mocha": "^1.3.0",
     "mocha": "^5.2.0",
     "mocha-junit-reporter": "^1.18.0",
-    "nyc": "^13.3.0",
+    "nyc": "^12.0.2",
     "rhea": "^0.3.9",
     "rhea-promise": "^0.1.13",
     "rimraf": "^2.6.2",

@AlexGhiondea AlexGhiondea merged commit 5b0e82c into Azure:master Mar 18, 2019
@ramya-rao-a ramya-rao-a mentioned this pull request Mar 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants