public void SendAndSyncReceive() { using (StompConnection stomp = new StompConnection("localhost", 61626)) { stomp.Subscribe("/queue/test"); stomp.Send("/queue/test", "Hello world!"); Message message = stomp.WaitForMessage(); Assert.AreEqual("Hello world!", message.Body); } }
public async Task StartAsync(CancellationToken cancellationToken) { var f = new StompWebSocketConnectionFactory(c => { c.Credentials = new NetworkCredential("admin", "admin"); }, logger); var e = new UriEndPoint(new Uri("ws://localhost:44112/websockets/messaging/websocket")); connection = await f.OpenAsync(e, cancellationToken); transaction = await connection.BeginAsync(cancellationToken : cancellationToken); cts = new CancellationTokenSource(); run = Task.Run(() => RunAsync(cts.Token)); }
public MoexInfoCXFeed(MoexInfoCXParameters settings) { this.settings = settings; connection = new StompConnection( new Uri(settings.BrokerUrl), new WebsocketTransportFactory(transportSettings), new StompWireFormat(), new StompLogger(Logger) ); connection.MessageReceived += Connection_MessageReceived; connection.StateChanged += Connection_StateChanged; }
static void Main(string[] args) { /* * //create the connection for activeMQ * //string hostname = "10.112.39.102"; * string hostname = "localhost"; * string stompServerPort = "61616"; * Uri uriSample = new Uri("activemq:tcp://"+hostname+":"+stompServerPort); * ConnectionFactory confSample = new ConnectionFactory(uriSample); * Connection con1 = (Connection)confSample.CreateConnection(); * con1.Start(); * * //create session * Session se1 = (Session)con1.CreateSession(); * * //Notification of acquisition * IDestination des = se1.GetTopic("topic.acquisitionCompleted"); * //IDestination des = se1.GetTopic("topic.acquisitionFailed"); * * //Notification of image * //IDestination des = se1.GetTopic("topic.imageCreated"); * //IDestination des = se1.GetTopic("topic.imageDeleted"); * * //Notification of presentation State * //IDestination des = se1.GetTopic("topic.presentationStateModified"); * //IDestination des = se1.GetTopic("topic.presentationStateDeleted"); * * //Notification of analysis * //IDestination des = se1.GetTopic("topic.analysisCreated"); * //IDestination des = se1.GetTopic("topic.analysisModified"); * //IDestination des = se1.GetTopic("topic.analysisModified"); * //IDestination des = se1.GetTopic("topic.analysisDeleted"); * * //Notification of FMS * //IDestination des = se1.GetTopic("topic.fmsCreated"); * //IDestination des = se1.GetTopic("topic.fmsModified"); * //IDestination des = se1.GetTopic("topic.fmsDeleted"); * * //Notification of Volume * //IDestination des = se1.GetTopic("topic.volumeCreated"); * * //Notification of Report * //IDestination des = se1.GetTopic("topic.reportCreated"); * //IDestination des = se1.GetTopic("topic.reportModified"); * //IDestination des = se1.GetTopic("topic.reportDeleted"); * * //Notification of Patient * //IDestination des = se1.GetTopic("topic.patientDeleted"); * * //Notification of AppState change * //IDestination des = se1.GetTopic("topic.appStateClosed"); * //IDestination des = se1.GetTopic("topic.appStateCreated"); * //IDestination des = se1.GetTopic("topic.appStateMinimized"); * //IDestination des = se1.GetTopic("topic.appStateRestored"); * //IDestination des = se1.GetTopic("tw"); * MessageConsumer consumerSample = (MessageConsumer)se1.CreateConsumer(des); * * //IMessage message = consumerSample.Receive(TimeSpan.FromMilliseconds(30000)); * consumerSample.Listener += new MessageListener(OnMessage); * Console.ReadLine(); * } * static void OnMessage(IMessage message) * { * Apache.NMS.ActiveMQ.Commands.ActiveMQTextMessage outputMsg = (Apache.NMS.ActiveMQ.Commands.ActiveMQTextMessage)message; * Console.WriteLine("stop to check the output message: " + outputMsg.Text); * * }*/ Config nc = new Config(); if (nc.getHost() == null || nc.getPort() == 0) { return; } List <string> topics = nc.getTopics(); StompConnection stomp = new StompConnection(nc.getHost(), nc.getPort()); string logFile = string.Empty; if (nc.getLogPath() != null) { logFile = nc.getLogPath(); } logFile = logFile.Substring(0, logFile.Length - 4); logFile = logFile + "_" + DateTime.Now.ToShortDateString() + "_" + DateTime.Now.ToShortTimeString() + ".log"; logFile = logFile.Replace("/", "_"); logFile = logFile.Replace(":", "_"); logFile = logFile.Replace(" ", "_"); logFile = System.Reflection.Assembly.GetExecutingAssembly().Location.Substring(0, System.Reflection.Assembly.GetExecutingAssembly().Location.LastIndexOf('\\')) + "\\" + logFile; stomp.setLogpath(logFile); foreach (string topic in topics) { stomp.subscribe(topic, stomp.OnMessage); } Console.ReadLine(); }
static void Main(string[] args) { /* //create the connection for activeMQ //string hostname = "10.112.39.102"; string hostname = "localhost"; string stompServerPort = "61616"; Uri uriSample = new Uri("activemq:tcp://"+hostname+":"+stompServerPort); ConnectionFactory confSample = new ConnectionFactory(uriSample); Connection con1 = (Connection)confSample.CreateConnection(); con1.Start(); //create session Session se1 = (Session)con1.CreateSession(); //Notification of acquisition IDestination des = se1.GetTopic("topic.acquisitionCompleted"); //IDestination des = se1.GetTopic("topic.acquisitionFailed"); //Notification of image //IDestination des = se1.GetTopic("topic.imageCreated"); //IDestination des = se1.GetTopic("topic.imageDeleted"); //Notification of presentation State //IDestination des = se1.GetTopic("topic.presentationStateModified"); //IDestination des = se1.GetTopic("topic.presentationStateDeleted"); //Notification of analysis //IDestination des = se1.GetTopic("topic.analysisCreated"); //IDestination des = se1.GetTopic("topic.analysisModified"); //IDestination des = se1.GetTopic("topic.analysisModified"); //IDestination des = se1.GetTopic("topic.analysisDeleted"); //Notification of FMS //IDestination des = se1.GetTopic("topic.fmsCreated"); //IDestination des = se1.GetTopic("topic.fmsModified"); //IDestination des = se1.GetTopic("topic.fmsDeleted"); //Notification of Volume //IDestination des = se1.GetTopic("topic.volumeCreated"); //Notification of Report //IDestination des = se1.GetTopic("topic.reportCreated"); //IDestination des = se1.GetTopic("topic.reportModified"); //IDestination des = se1.GetTopic("topic.reportDeleted"); //Notification of Patient //IDestination des = se1.GetTopic("topic.patientDeleted"); //Notification of AppState change //IDestination des = se1.GetTopic("topic.appStateClosed"); //IDestination des = se1.GetTopic("topic.appStateCreated"); //IDestination des = se1.GetTopic("topic.appStateMinimized"); //IDestination des = se1.GetTopic("topic.appStateRestored"); //IDestination des = se1.GetTopic("tw"); MessageConsumer consumerSample = (MessageConsumer)se1.CreateConsumer(des); //IMessage message = consumerSample.Receive(TimeSpan.FromMilliseconds(30000)); consumerSample.Listener += new MessageListener(OnMessage); Console.ReadLine(); } static void OnMessage(IMessage message) { Apache.NMS.ActiveMQ.Commands.ActiveMQTextMessage outputMsg = (Apache.NMS.ActiveMQ.Commands.ActiveMQTextMessage)message; Console.WriteLine("stop to check the output message: " + outputMsg.Text); }*/ Config nc = new Config(); if (nc.getHost() == null || nc.getPort() == 0) return; List<string> topics = nc.getTopics(); StompConnection stomp = new StompConnection(nc.getHost(), nc.getPort()); string logFile = string.Empty; if (nc.getLogPath() != null) logFile = nc.getLogPath(); logFile = logFile.Substring(0, logFile.Length - 4); logFile = logFile + "_" + DateTime.Now.ToShortDateString() + "_" + DateTime.Now.ToShortTimeString() + ".log"; logFile = logFile.Replace("/", "_"); logFile = logFile.Replace(":", "_"); logFile = logFile.Replace(" ", "_"); logFile = System.Reflection.Assembly.GetExecutingAssembly().Location.Substring(0, System.Reflection.Assembly.GetExecutingAssembly().Location.LastIndexOf('\\')) + "\\" + logFile; stomp.setLogpath(logFile); foreach (string topic in topics) { stomp.subscribe(topic, stomp.OnMessage); } Console.ReadLine(); }