Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Event Hubs] Circular dependencies from rhea-promise #27252

Closed
EskelCz opened this issue Sep 26, 2023 · 13 comments
Closed

[Event Hubs] Circular dependencies from rhea-promise #27252

EskelCz opened this issue Sep 26, 2023 · 13 comments
Assignees
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. Event Hubs question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@EskelCz
Copy link

EskelCz commented Sep 26, 2023

  • Package Name: @azure/event-hubs
  • Package Version: 5.11.2
  • Operating system: Mac OS
  • [*] nodejs
    • version: tried 18.13.0 and 20.7.0

Describe the bug
When building for browser with Rollup, with the configuration from @azure/event-hubs documentation, I'm getting these two circular dependencies:

(!) Circular dependencies

node_modules/rhea-promise/dist/lib/eventContext.js -> node_modules/rhea-promise/dist/lib/connection.js -> node_modules/rhea-promise/dist/lib/session.js -> node_modules/rhea-promise/dist/lib/receiver.js -> node_modules/rhea-promise/dist/lib/link.js -> node_modules/rhea-promise/dist/lib/util/utils.js -> node_modules/rhea-promise/dist/lib/eventContext.js

node_modules/rhea-promise/dist/lib/connection.js -> node_modules/rhea-promise/dist/lib/container.js -> node_modules/rhea-promise/dist/lib/connection.js

To Reproduce
Steps to reproduce the behavior:

  1. Install these dependencies:
  "devDependencies": {
    "@rollup/plugin-commonjs": "^25.0.4",
    "@rollup/plugin-inject": "^5.0.3",
    "@rollup/plugin-node-resolve": "^15.2.1",
    "buffer": "^6.0.3",
    "os-browserify": "^0.3.0",
    "path-browserify": "^1.0.1",
    "rollup-plugin-shim": "^1.0.0"
  },
  "peerDependencies": {
    "typescript": "^5.0.0"
  },
  "dependencies": {
    "@azure/event-hubs": "5.11.2"
  }
  1. Use this rollup config:
import nodeResolve from '@rollup/plugin-node-resolve'
import cjs from '@rollup/plugin-commonjs'
import shim from 'rollup-plugin-shim'
import inject from '@rollup/plugin-inject'

export default {
  input: 'src/index.js',
  output: {
    file: 'dist/bundle.js',
    format: 'iife',
    name: 'bundle'
  },
  plugins: [
    shim({
      fs: `export default {}`,
      net: `export default {}`,
      tls: `export default {}`,
      path: `export default {}`,
      dns: `export function resolve() { }`,
      os: `
        export const type = 1;
        export const release = 1;
      `
    }),
    nodeResolve({
      mainFields: ['module', 'browser'],
      preferBuiltins: false
    }),
    cjs(),
    inject({
      modules: {
        Buffer: ['buffer', 'Buffer'],
        process: 'process'
      },
      exclude: ['./**/package.json']
    })
  ]
}

Expected behavior
Build without errors

Additional context
I think it might be this issue: amqp/rhea-promise#47

@github-actions github-actions bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Sep 26, 2023
@EskelCz
Copy link
Author

EskelCz commented Sep 26, 2023

Do you happen to have an ESM version of @azure/event-hubs in the works? That would be the best solution in my opinion.
The current build has 875 KB, which is crazy. Unminified, but still, not usable even if it was half that size.

@jeremymeng
Copy link
Member

@EskelCz We are packing ESM files too. Maybe for some reason the bundler was not using them? https://unpkg.com/browse/@azure/event-hubs@5.11.2/dist-esm/

"module": "dist-esm/src/index.js",

@deyaaeldeen deyaaeldeen self-assigned this Sep 26, 2023
@github-actions github-actions bot removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Sep 26, 2023
@EskelCz
Copy link
Author

EskelCz commented Sep 26, 2023

@jeremymeng Nice, I'll give that a try. Why isn't there anything about it in the readme? Or is it documented somewhere else? Thanks

@EskelCz
Copy link
Author

EskelCz commented Sep 27, 2023

When I try building it as ESM and import from @azure/event-hubs, I get this bundling error instead:

[!] RollupError: "OperationTimeoutError" is not exported by "node_modules/rhea-promise/dist/lib/index.js", imported by "node_modules/@azure/core-amqp/dist-esm/src/util/lock.js".
https://rollupjs.org/troubleshooting/#error-name-is-not-exported-by-module
node_modules/@azure/core-amqp/dist-esm/src/util/lock.js (4:9)
2: // Licensed under the MIT license.
3: import { AbortError } from "@azure/abort-controller";
4: import { OperationTimeoutError } from "rhea-promise";
            ^

Again the issue seems to be the rhea-promise package.

@EskelCz
Copy link
Author

EskelCz commented Oct 2, 2023

When thinking about it more in-depth, we probably don't need an SDK at all... all we need is something like five lines of code to send the https request from the front-end, with a domain whitelist in the back-end event hub. Is such a setup possible with event hubs?

@jeremymeng
Copy link
Member

@EskelCz I am not aware of any HTTP/REST api to publish events to Event Hubs. Maybe Azure Functions' output binding could work for you? https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-event-hubs-output?tabs=python-v2%2Cisolated-process%2Cnodejs-v4%2Cfunctionsv2%2Cextensionv5&pivots=programming-language-javascript

@jeremymeng
Copy link
Member

When I try building it as ESM and import from @Azure/event-hubs, I get this bundling error instead:

[!] RollupError: "OperationTimeoutError" is not exported by "node_modules/rhea-promise/dist/lib/index.js", imported by "node_modules/@azure/core-amqp/dist-esm/src/util/lock.js".
https://rollupjs.org/troubleshooting/#error-name-is-not-exported-by-module
node_modules/@azure/core-amqp/dist-esm/src/util/lock.js (4:9)
2: // Licensed under the MIT license.
3: import { AbortError } from "@azure/abort-controller";
4: import { OperationTimeoutError } from "rhea-promise";
            ^

Again the issue seems to be the rhea-promise package.

I am not sure why Rollup couldn't find it but rhea-promise has the type exported: https://unpkg.com/browse/rhea-promise@3.0.1/typings/lib/index.d.ts

@EskelCz
Copy link
Author

EskelCz commented Oct 3, 2023

@jeremymeng Not sure, I'm not bundling it as typescript, so maybe the dependency is not compiled to javascript properly?
Here I made a minimalistic reproduction demo: https://stackblitz.com/edit/event-hub-esm
You can get the same error by running npm run build or rollup --config

@deyaaeldeen
Copy link
Member

This is a rhea promise issue. I opened amqp/rhea-promise#105 to break the cycles.

@jeremymeng
Copy link
Member

@EskelCz that error is due to rhea-promise only provides commonjs. You can fix it by using @rollup/plugin-commonjs. With that said, the circular dep warning is still there.
https://stackblitz.com/edit/event-hub-esm-ggjynf?file=rollup.config.js,index.js

@EskelCz
Copy link
Author

EskelCz commented Oct 12, 2023

@deyaaeldeen @jeremymeng Thanks, that solves the build. But I was hoping for a much larger effect on the size of the bundle. It's still over 500 KB. Why do we need 14 703 lines of code to send a simple https request to the event hub from the front-end?
Is there another way?

@jeremymeng
Copy link
Member

jeremymeng commented Oct 12, 2023

@EskelCz Azure Event Hubs service does not use HTTP/HTTPS protocol. It uses AMQP thus our SDK requires AMQP supporting libraries (please see here for an overview: https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-amqp-overview#amqp-10-technical-features)

If all you need is to write some events to event hubs, the azure function output binding might be enough for you. I suppose that you can send HTTPS request to the azure function, which in turn writes to Event Hubs. https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-event-hubs-output?tabs=python-v2%2Cisolated-process%2Cnodejs-v4%2Cfunctionsv2%2Cextensionv5&pivots=programming-language-javascript

EDITED:

After some search, I see that the service does support some subset of functionalities through REST, but we don't have SDK support for that, so you would need to work with raw REST API https://learn.microsoft.com/en-us/rest/api/eventhub/event-hubs-runtime-rest

@EskelCz
Copy link
Author

EskelCz commented Oct 13, 2023

@jeremymeng That's it, REST is just what I need. Thanks a lot.

@EskelCz EskelCz closed this as completed Oct 13, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jan 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. Event Hubs question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
Status: Done
Development

No branches or pull requests

3 participants