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 ResetAll() in topicaliases to prevent error on reconnection #277

Conversation

shirou
Copy link
Contributor

@shirou shirou commented Nov 15, 2024

Related: #271 and #276

This PR introduce ResetAll method in TAHandler. ResetAll should be called before reconnect. If not, topic alias is used after reconnect, and causes Protocol Error.

Here is a minimal sample code to use TAHandler with autopaho.

	maxTopicAlias := uint16(100)
	ta := topicaliases.NewTAHandler(maxTopicAlias)

	cliCfg := autopaho.ClientConfig{
		ServerUrls:                    []*url.URL{u},
		CleanStartOnInitialConnection: false,
		OnConnectionUp: func(cm *autopaho.ConnectionManager, connAck *paho.Connack) {
			ta.ResetAll()
		},
		ConnectPacketBuilder: func(c *paho.Connect, u *url.URL) (*paho.Connect, error) {
			c.Properties = &paho.ConnectProperties{
				TopicAliasMaximum: &maxTopicAlias,
			}
			return c, nil
		},
		ClientConfig: paho.ClientConfig{
			PublishHook: ta.PublishHook,
		},
	}

@MattBrittan MattBrittan merged commit 32af1f8 into eclipse-paho:master Nov 15, 2024
1 check passed
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.

2 participants