Added scripted use cases
Minor changes to logging
This commit is contained in:
@@ -53,7 +53,7 @@ public class Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void startServer(String nioFrameworkType) throws IOException {
|
public void startServer(String nioFrameworkType) throws IOException {
|
||||||
LOG.info("Starting server with " + nioFrameworkType + " connectors");
|
System.out.println("Starting server with " + nioFrameworkType + " connectors");
|
||||||
messaging = SimpleMessaging.getInstance();
|
messaging = SimpleMessaging.getInstance();
|
||||||
messaging.init();
|
messaging.init();
|
||||||
|
|
||||||
@@ -66,10 +66,10 @@ public class Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void stopServer() {
|
public void stopServer() {
|
||||||
LOG.info("Server stopping...");
|
System.out.println("Server stopping...");
|
||||||
messaging.stop();
|
messaging.stop();
|
||||||
m_acceptor.close();
|
m_acceptor.close();
|
||||||
LOG.info("Server stopped");
|
System.out.println("Server stopped");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ log4j.rootLogger=ERROR, A1
|
|||||||
#log4j.logger.org.dna.mqtt.moquette.proto.MQTTLoggingFilter=DEBUG
|
#log4j.logger.org.dna.mqtt.moquette.proto.MQTTLoggingFilter=DEBUG
|
||||||
#log4j.logger.org.dna.mqtt.moquette.proto.PublishDecoder=DEBUG
|
#log4j.logger.org.dna.mqtt.moquette.proto.PublishDecoder=DEBUG
|
||||||
|
|
||||||
log4j.logger.org.dna.mqtt=INFO
|
log4j.logger.org.dna.mqtt=WARN
|
||||||
log4j.logger.org.dna.mqtt.moquette.server.ServerIntegrationFuseTest=DEBUG
|
log4j.logger.org.dna.mqtt.moquette.server.ServerIntegrationFuseTest=DEBUG
|
||||||
log4j.logger.org.dna.mqtt.moquette.messaging.spi.impl.ProtocolProcessor=DEBUG
|
log4j.logger.org.dna.mqtt.moquette.messaging.spi.impl.ProtocolProcessor=WARN
|
||||||
|
|
||||||
# A1 is set to be a ConsoleAppender.
|
# A1 is set to be a ConsoleAppender.
|
||||||
log4j.appender.A1=org.apache.log4j.ConsoleAppender
|
log4j.appender.A1=org.apache.log4j.ConsoleAppender
|
||||||
|
|||||||
+18
-18
@@ -1,19 +1,19 @@
|
|||||||
# Set root logger level to DEBUG and its only appender to A1.
|
# Set root logger level to DEBUG and its only appender to A1.
|
||||||
#log4j.rootLogger=ERROR, A1
|
#log4j.rootLogger=ERROR, A1
|
||||||
log4j.rootLogger=INFO, A1
|
log4j.rootLogger=INFO, A1
|
||||||
#log4j.rootLogger=WARN, A1
|
#log4j.rootLogger=WARN, A1
|
||||||
#log4j.logger.org.dna.mqtt.moquette.client=WARN
|
#log4j.logger.org.dna.mqtt.moquette.client=WARN
|
||||||
#log4j.logger.org.mina=WARN
|
#log4j.logger.org.mina=WARN
|
||||||
#log4j.logger.org.dna.mqtt.moquette.server=DEBUG
|
#log4j.logger.org.dna.mqtt.moquette.server=DEBUG
|
||||||
#log4j.logger.org.dna.mqtt.moquette.messaging=DEBUG
|
#log4j.logger.org.dna.mqtt.moquette.messaging=DEBUG
|
||||||
#log4j.logger.org.dna.mqtt.moquette.proto.MQTTLoggingFilter=DEBUG
|
#log4j.logger.org.dna.mqtt.moquette.proto.MQTTLoggingFilter=DEBUG
|
||||||
#log4j.logger.org.dna.mqtt.moquette.proto.PublishDecoder=DEBUG
|
#log4j.logger.org.dna.mqtt.moquette.proto.PublishDecoder=DEBUG
|
||||||
|
|
||||||
log4j.logger.org.dna.mqtt.bechnmark=INFO
|
log4j.logger.org.dna.mqtt.bechnmark=INFO
|
||||||
|
|
||||||
# A1 is set to be a ConsoleAppender.
|
# A1 is set to be a ConsoleAppender.
|
||||||
log4j.appender.A1=org.apache.log4j.ConsoleAppender
|
log4j.appender.A1=org.apache.log4j.ConsoleAppender
|
||||||
|
|
||||||
# A1 uses PatternLayout.
|
# A1 uses PatternLayout.
|
||||||
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
|
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
|
||||||
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c{1} %x - %m%n
|
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c{1} %x - %m%n
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import org.eclipse.paho.client.mqttv3.MqttClient
|
||||||
|
import org.eclipse.paho.client.mqttv3.MqttMessage
|
||||||
|
import org.eclipse.paho.client.mqttv3.MqttException
|
||||||
|
import org.eclipse.paho.client.mqttv3.MqttDefaultFilePersistence
|
||||||
|
|
||||||
|
String tmpDir = System.getProperty("java.io.tmpdir")
|
||||||
|
MqttDefaultFilePersistence dataStore = new MqttDefaultFilePersistence(tmpDir)
|
||||||
|
|
||||||
|
MqttClient client = new MqttClient("tcp://localhost:1883", "SampleClient", dataStore)
|
||||||
|
client.connect()
|
||||||
|
println "connected"
|
||||||
|
(1..10).each {
|
||||||
|
//MqttMessage message = new MqttMessage("Hello world!! $it".toString().bytes)
|
||||||
|
String s = "Hello World!! $it"
|
||||||
|
MqttMessage message = new MqttMessage(s.bytes)
|
||||||
|
message.qos = 2
|
||||||
|
message.retained = true
|
||||||
|
print "publishing.."
|
||||||
|
client.getTopic("log").publish(message)
|
||||||
|
println "published"
|
||||||
|
}
|
||||||
|
|
||||||
|
client.disconnect()
|
||||||
|
println "disconnected"
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
require 'rubygems'
|
||||||
|
require 'mqtt'
|
||||||
|
|
||||||
|
MQTT::Client.connect('localhost',1883) do |client|
|
||||||
|
client.get('#') do |topic,message|
|
||||||
|
puts "#{topic}: #{message}"
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
@GrabResolver(name='Paho', root='https://repo.eclipse.org/content/repositories/paho-releases/")
|
||||||
|
@Grab(group='org.eclipse.paho', module='mqtt-client', version='0.4.0')
|
||||||
|
|
||||||
|
import org.eclipse.paho.client.mqttv3.MqttClient
|
||||||
|
import org.eclipse.paho.client.mqttv3.MqttMessage
|
||||||
|
import org.eclipse.paho.client.mqttv3.MqttException
|
||||||
|
import org.eclipse.paho.client.mqttv3.MqttDefaultFilePersistence
|
||||||
|
|
||||||
|
String tmpDir = System.getProperty("java.io.tmpdir")
|
||||||
|
MqttDefaultFilePersistence dataStore = new MqttDefaultFilePersistence(tmpDir)
|
||||||
|
|
||||||
|
MqttClient client = new MqttClient("tcp://localhost:1883", "SampleClient", dataStore)
|
||||||
|
client.connect()
|
||||||
|
MqttMessage message = new MqttMessage('Hello world!!'.bytes)
|
||||||
|
message.setQos(2)
|
||||||
|
print "publishing.."
|
||||||
|
client.getTopic("log").publish(message)
|
||||||
|
println "published"
|
||||||
|
client.disconnect()
|
||||||
|
println "disconnected"
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
@GrabResolver(name='Paho', root='https://repo.eclipse.org/content/repositories/paho-releases/')
|
||||||
|
@Grab(group='org.eclipse.paho', module='mqtt-client', version='0.4.0')
|
||||||
|
|
||||||
|
import org.eclipse.paho.client.mqttv3.MqttClient
|
||||||
|
import org.eclipse.paho.client.mqttv3.MqttMessage
|
||||||
|
import org.eclipse.paho.client.mqttv3.MqttException
|
||||||
|
import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence
|
||||||
|
|
||||||
|
String tmpDir = System.getProperty("java.io.tmpdir")
|
||||||
|
MqttDefaultFilePersistence dataStore = new MqttDefaultFilePersistence(tmpDir)
|
||||||
|
|
||||||
|
MqttClient client = new MqttClient("tcp://localhost:1883", "PublisherClient", dataStore)
|
||||||
|
client.connect()
|
||||||
|
MqttMessage message = new MqttMessage('Hello world!!'.bytes)
|
||||||
|
message.setQos(0)
|
||||||
|
print "publishing.."
|
||||||
|
long startTime = System.currentTimeMillis()
|
||||||
|
(1..1000000).each {
|
||||||
|
client.publish('topic', 'Hello world!!'.bytes, 0, false)
|
||||||
|
}
|
||||||
|
client.publish('/exit', 'Exit'.bytes, 0, false)
|
||||||
|
long stopTime = System.currentTimeMillis()
|
||||||
|
long spentTime = stopTime -startTime
|
||||||
|
println "published in ${spentTime} ms"
|
||||||
|
client.disconnect()
|
||||||
|
println "disconnected"
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
@GrabResolver(name='Paho', root='https://repo.eclipse.org/content/repositories/paho-releases/')
|
||||||
|
@Grab(group='org.eclipse.paho', module='mqtt-client', version='0.4.0')
|
||||||
|
|
||||||
|
import org.eclipse.paho.client.mqttv3.MqttClient
|
||||||
|
import org.eclipse.paho.client.mqttv3.MqttMessage
|
||||||
|
import org.eclipse.paho.client.mqttv3.MqttException
|
||||||
|
import org.eclipse.paho.client.mqttv3.MqttCallback
|
||||||
|
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken
|
||||||
|
import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence
|
||||||
|
import java.util.concurrent.CountDownLatch
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class SubscriberCallback implements MqttCallback {
|
||||||
|
|
||||||
|
int m_numReceived = 0
|
||||||
|
long m_startTime
|
||||||
|
boolean firstMessageReceived = false
|
||||||
|
|
||||||
|
private CountDownLatch m_latch = new CountDownLatch(1)
|
||||||
|
|
||||||
|
void waitFinish() {
|
||||||
|
m_latch.await()
|
||||||
|
}
|
||||||
|
|
||||||
|
public void connectionLost(Throwable cause) {
|
||||||
|
m_latch.countDown()
|
||||||
|
}
|
||||||
|
|
||||||
|
public void messageArrived(String topic, MqttMessage message) throws Exception {
|
||||||
|
//println "Received message ${new String(message.payload)} on topic [${topic}]"
|
||||||
|
if (!firstMessageReceived) {
|
||||||
|
m_startTime = System.currentTimeMillis()
|
||||||
|
firstMessageReceived = true
|
||||||
|
}
|
||||||
|
if (topic == "/exit") {
|
||||||
|
long stopTime = System.currentTimeMillis()
|
||||||
|
long spentTime = stopTime - m_startTime
|
||||||
|
println "/exit received"
|
||||||
|
println "subscriber disconnected, received ${m_numReceived} messages in ${spentTime} ms"
|
||||||
|
client.disconnect()
|
||||||
|
m_latch.countDown()
|
||||||
|
} else {
|
||||||
|
m_numReceived++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deliveryComplete(IMqttDeliveryToken token) {
|
||||||
|
//To change body of implemented methods use File | Settings | File Templates.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String tmpDir = System.getProperty("java.io.tmpdir")
|
||||||
|
MqttDefaultFilePersistence dataStore = new MqttDefaultFilePersistence(tmpDir)
|
||||||
|
|
||||||
|
MqttClient client = new MqttClient("tcp://localhost:1883", "SubscriberClient", dataStore)
|
||||||
|
def callback = new SubscriberCallback()
|
||||||
|
client.callback = callback
|
||||||
|
client.connect()
|
||||||
|
client.subscribe("topic", 0)
|
||||||
|
println "subscribed to topic"
|
||||||
|
client.subscribe("/exit", 0)
|
||||||
|
println "subscribed to /exit"
|
||||||
|
|
||||||
|
callback.waitFinish()
|
||||||
Reference in New Issue
Block a user