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

Add ClientId option on MQTT connect message #303

Merged
merged 8 commits into from
May 21, 2018
Merged

Add ClientId option on MQTT connect message #303

merged 8 commits into from
May 21, 2018

Conversation

sashaafm
Copy link
Contributor

@sashaafm sashaafm commented May 8, 2018

This PR allows for the client_id to be set by the user, when performing an MQTT connect message, as specified by the MQTT protocol.

We, at Talkdesk, need this feature as we rely on the client ID for certain validations on connect, thus we must set a custom Client ID on our Tsung clients so they may successfully connect to our MQTT brokers.

Since this ID is part of the MQTT protocol we also believe it makes sense to allow the user to set it as he wishes. If a user wants to prefix the ID with a string related to Tsung (e.g., with tsung- as current commit does by default), he may easily do it with either a Dynamic Variable.

This commit allows for the `client_id` to be set by the user, when
performing an MQTT connect message, as specified by the MQTT protocol.
#state_rcv{session = MqttSession}) ->
ClientId = ["tsung-", ts_utils:randombinstr(10)],
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not very deeply familiar with MQTT, but if client ID is required, we could generate it in case it is not provided.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had thought about that, but it seems that anyone using the protocol may quickly generate it using Tsung facilities.

Do you reckon it would be better to have another function clause which automatically generates the Client ID, when it's not provided?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Like I said, if this is required, then I'd say yes. Otherwise this would be a breaking change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've submitted a new commit which hopefully takes care of this. However, I'll need someone to validate it, since my Erlang foo is quite low.

Copy link
Contributor

Choose a reason for hiding this comment

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

We also added two unit tests scenarios, providing a custom client ID or using the default implementation. So far it does not seem to be a breaking change.

@tisba
Copy link
Collaborator

tisba commented May 8, 2018

One more thing, are you sure, you don't have to change https://github.com/processone/tsung/blob/develop/src/tsung_controller/ts_config_mqtt.erl#L47 to include the new config option?

This commits introduces the automatic generation of the Client ID on
MQTT connect, when it's missing from the MQTT Request record.
@sashaafm
Copy link
Contributor Author

sashaafm commented May 8, 2018

@tisba you're probably right, didn't notice that file. Going to take a look and provide the necessary changes.

Sasha Fonseca added 2 commits May 8, 2018 15:30
This commit adds the necessary config to properly use the `client_id`
attribute on a MQTT connect message.
@sashaafm
Copy link
Contributor Author

sashaafm commented May 9, 2018

@tisba when you can would you mind reviewing the PR again? We'd like to start using these changes as soon as possible

@sashaafm
Copy link
Contributor Author

sashaafm commented May 9, 2018

We've been running some local experiments and it seems the client_id isn't being properly replaced from the XML into the MQTT request (it's inserting %%_client_id%%).

We've been looking at the code, but can't figure out what the problem is. Any help would be appreciated.

EDIT: It correctly works with an hard-coded value in the client_id XML attribute

EDIT2: We've fixed this in the next commit

@picaoao
Copy link
Contributor

picaoao commented May 18, 2018

@tisba @nniclausse Could you please have at this PR, and if ok merge it ? 🙏

@tisba
Copy link
Collaborator

tisba commented May 18, 2018

Hey @picaoao. This looks like a nice solution!

Unfortunately I cannot merge things, only @nniclausse can :)

@nniclausse
Copy link
Contributor

The PR seems fine; it would be perfect if you document the new option in the mqtt part of the doc.

@sashaafm
Copy link
Contributor Author

@nniclausse I've pushed the documentation changes. Do you want me to squash all commits?

@nniclausse nniclausse merged commit fe0fe29 into processone:develop May 21, 2018
@nniclausse
Copy link
Contributor

that's fine. merged, thanks !

@nniclausse nniclausse added this to the 1.8.0 milestone Feb 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants