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

[service-bus] Allow users to call open() on a Sender and initialize the connection #8329

Conversation

richardpark-msft
Copy link
Member

Adding an .open() method on Sender to allow users to control when connection and link initialization occur.

Fixes #3212

Allows users to frontload the connection overhead and not have to see it on first send.
@richardpark-msft richardpark-msft force-pushed the richardpark-sb-non-lazy-open branch from d32ee74 to 346634f Compare April 13, 2020 19:35
* Ensures that the Service Bus connection and sender link is open.
*
* This method will be called on-demand by the Sender. Only call this method if you need
* to force the opening of the connection and link.
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs some work... I'd like us to convey that this is optional, not everyone should feel the need to use it. And a guidance on when one should consider calling it.

And also update our send code snippet in our readme and/or samples with something like the below:

Add await sender.open() before your first send operation if you want to front load the work of setting up the AMQP link to the service. Doing this will save your first send operation from spending the time to do the same

Copy link
Member

Choose a reason for hiding this comment

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

Agree with above, but it's AMQP connection and link I think?

Copy link
Contributor

Choose a reason for hiding this comment

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

well, not always.

If you have used the client for any of the non send operations, then the AMQP connection is already up, all we need to do is set up the link

Copy link
Contributor

@ramya-rao-a ramya-rao-a Apr 13, 2020

Choose a reason for hiding this comment

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

In the interest of not going too much details, I would suggest to sticking to "link" only.

I would recommend to use my above suggestion in samples and the below for the docs on this public method

Opens the AMQP link to Azure Service Bus from the sender. It is not necessary to call this method in order to use the sender. It is recommended to call this before your first send() or sendBatch() calls if you want to front load the work of setting up the AMQP link to the service. Doing this will save your first send operation from spending the time to do the same.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated, adding in some formatting.

I did remove the Doing this will save... part only because it seemed redundant with the prior sentences.

Copy link
Member Author

Choose a reason for hiding this comment

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

(unresolving - didn't get to the sample yet)

Copy link
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 - pre-critique (I don't want to push again and have my tests stop!)

(this goes into the ### Send messages snippet):

// Optionally, you can call sender.open() if you want to front load the work of setting
// up the AMQP link to the service. If not called, the sender will call open() on your behalf
// on the first send operation.
//
// await sender.open()

Copy link
Contributor

Choose a reason for hiding this comment

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

"Optionally, you can call sender.open()" -> "Optionally, you can await on sender.open() "to double down that this is an async operation or "Optionally, you can call await sender.open()"

"on the first send operation." -> "in the first send operation." ?

Copy link
Member

@bterlson bterlson left a comment

Choose a reason for hiding this comment

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

API change looks good.

@ramya-rao-a
Copy link
Contributor

What happens when user calls open() and internally the initialization is already in progress? Some valid use cases where this can happen are

  • The background process for bringing up broken links are in process
  • I create a sender and pass it around to 4 functions, each of them call open() first and then send()

@richardpark-msft
Copy link
Member Author

What happens when user calls open() and internally the initialization is already in progress? Some valid use cases where this can happen are

* The background process for bringing up broken links are in process

I'm not sure if this is affected at all by what I've done, mostly because this code is the same as the code that was called before. So I suppose this would be very similar to what would happen if the user called send() while this same process was happening.

(also, can't tell if you're saying - this is a new issue or an existing one)

* I create a sender and pass it around to 4 functions, each of them call `open()` first and then `send()`

This is totally legitimate - there's a lock that I need to migrate into the .open() call which will prevent this. In the next push. :)

@richardpark-msft
Copy link
Member Author

@ramya-rao-a - I migrated the this.senderLink check into .open() which seems to do what we wanted. Let me know if that's not what you were talking about.

- Wasn't properly awaiting in my lock test which was causing the tests to hang on exit
- Change over to just purely using async rather than having a hybrid which could cause inconsistencies with the way errors came back.
- Adding in a return type that I didn't mean to omit.
@richardpark-msft
Copy link
Member Author

/azp run js - servicebus - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@richardpark-msft
Copy link
Member Author

/azp run js - servicebus - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

…l async function _must_ call reject() explicitly.

- Updating readme with some wording changes from Ramya.
@richardpark-msft
Copy link
Member Author

/azp run js - servicebus - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

- Bring back missing log message for acquiring the lock
- Update samples to show the .open() call
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants