package vs;

import java.util.Date;

import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;

public class Publisher {
	public static void main(String... args) {
		var clientId = MqttClient.generateClientId();
		try (var client = new MqttClient(Conf.BROKER, clientId)) {
			client.connect();
			var message = new MqttMessage();
			for (var i = 0; i < 30; i++) {
				var m = "[" + clientId + "] message " + i + ": " + (new Date()).toString();
				message.setPayload(m.getBytes());
				client.publish(Conf.TOPIC, message);
			}
		} catch (MqttException e) {
			System.err.println(e.getMessage());
		}
	}
}
