static void Main(string[] args) { RedisCluster.register(); initialise("app", "session-id-role", "session-id-node-1", "localhost", "0"); var app = spawn <Unit, string>( Name: "application", Setup: () => ignore(spawn <string>("child", msg => Console.WriteLine($"{msg} : {sessionId()}"), ProcessFlags.PersistInbox)), Inbox: (_, msg) => fwdChild("child"), Flags: ProcessFlags.PersistInbox); while (true) { var sid = SessionId.Generate(); withSession(sid, () => { sessionId(); tell(app, "Hello"); }); if (Console.ReadKey().Key == ConsoleKey.Escape) { break; } } }
public static void AskReplyError() { shutdownAll(); // Let Language Ext know that Redis exists RedisCluster.register(); // Connect to the Redis cluster Cluster.connect("redis", "redis-test", "localhost", "0"); var world = spawn <ProcessId, string>("world", () => spawn <string>("hello", msg => failwith <Unit>("Failed!"), ProcessFlags.PersistInbox), (pid, msg) => { Assert.Throws <ProcessException>(() => { ask <string>(pid, msg); }); return(pid); }, ProcessFlags.PersistInbox ); tell(world, "error throwing test"); }
public static void AskReplyError() { shutdownAll(); // Let Language Ext know that Redis exists RedisCluster.register(); // Connect to the Redis cluster ProcessConfig.initialise("sys", "global", "redis-test", "localhost", "0"); try { var world = spawn <ProcessId, string>("world", () => spawn <string>("hello", msg => failwith <Unit>("Failed!"), ProcessFlags.PersistInbox), (pid, msg) => { ask <string>(pid, msg); return(pid); }, ProcessFlags.PersistInbox ); tell(world, "error throwing test"); } catch (Exception e) { Debug.Assert(e.Message == "Process issue: Failed!"); } Thread.Sleep(1000); }
// // Launch a process that adds the int sent in a message to its state // Then calls itself after a second to do the same again. The state value gradually // increases. // // If you stop the sample and restart you'll notice the state has been persisted // static void Main(string[] args) { // Log what's going on ProcessSystemLog.Subscribe(Console.WriteLine); // Let Language Ext know that Redis exists RedisCluster.register(); // Connect to the Redis cluster ProcessConfig.initialise("sys", "global", "redis-test", "localhost", "0"); // Spawn the process var pid = spawn <string>("redis-inbox-sample", Inbox, ProcessFlags.PersistInbox); Console.WriteLine("Press a key to add 100 messages to the process queue"); Console.WriteLine(" - The process queue has a Thread.Sleep(200) in it"); Console.WriteLine(" - So it takes 20 seconds to get through all of the messages"); Console.WriteLine(" - If you quit the sample and restart, you should see the "); Console.WriteLine(" - inbox has persisted."); Console.WriteLine(""); Console.WriteLine("Press a key"); Console.ReadKey(); var rnd = new Random(); for (var i = 0; i < 100; i++) { tell(pid, "Message sent: " + DateTime.Now + " " + DateTime.Now.Ticks + " " + rnd.Next()); } Console.ReadKey(); }
public static void AskReplyError() { lock (sync) { shutdownAll(); Assert.True(Systems.Count == 0); // Let Language Ext know that Redis exists RedisCluster.register(); // Connect to the Redis cluster ProcessConfig.initialise("sys", "global", "redis-ask-reply-test", "localhost", "0"); var world = spawn <ProcessId, string>("world", () => spawn <string>("hello", msg => failwith <Unit>("Failed!"), ProcessFlags.PersistInbox), (pid, msg) => { Assert.Throws <ProcessException>(() => { ask <string>(pid, msg); }); return(pid); }, ProcessFlags.PersistInbox ); tell(world, "error throwing test"); Thread.Sleep(100); } }
static void Main(string[] args) { var ping = ProcessId.Top["redis-watcher-a"]["user"]["ping"]; // Let Language Ext know that Redis exists RedisCluster.register(); // Connect to the Redis cluster Cluster.connect("redis", "redis-watcher-b", "localhost", "0", "global"); var pong = spawn <string>( Name: "pong", Inbox: msg => { Console.WriteLine(msg); tell(ping, "ping", 1000 * ms); }, Terminated: pid => Console.WriteLine(pid + " is pushing up the daisies"), Flags: ProcessFlags.PersistInbox ); watch(pong, ping); Console.ReadKey(); }
static void Main(string[] args) { RedisCluster.register(); initialise("app", "schedule-test", "schedule-test1", "localhost", "0"); //RunInbox(); RunInboxAppendNum(); //RunInboxAppend(); }
static void Main(string[] args) { // Remove this to get on-screen logging ProcessSystemLog.Subscribe(Console.WriteLine); // Let Language Ext know that Redis exists RedisCluster.register(); // Connect to the Redis cluster ProcessConfig.initialiseFileSystem("session-test-1"); var ping = ProcessId.None; var pong = ProcessId.None; // Start a process which simply writes the messages it receives to std-out var logger = spawn <string>("logger", x => Console.WriteLine(x)); sessionStart("xyz", 20 * seconds, "live"); // Ping process ping = spawn <string>("ping", msg => { tell(logger, msg); var txt = hasSession() ? sessionId().ToString() : "expired"; var val = sessionGetData <int>("test"); sessionSetData("test", val.FirstOrDefault() + 1); tell(pong, $"ping-{txt}-{val.FirstOrDefault()}", TimeSpan.FromMilliseconds(1000)); }); // Pong process pong = spawn <string>("pong", msg => { tell(logger, msg); var txt = hasSession() ? sessionId().ToString() : "expired"; var val = sessionGetData <int>("test"); sessionSetData("test", val.FirstOrDefault() + 1); tell(ping, $"pong-{txt}-{val.FirstOrDefault()}", TimeSpan.FromMilliseconds(1000)); }); // Trigger tell(pong, "start"); Console.ReadKey(); }
public static void Main(string[] args) { // Remove this to get on-screen logging ProcessSystemLog.Subscribe(Console.WriteLine); RedisCluster.register(); ProcessConfig.initialiseFileSystem("ping-pong-1"); var ping = ProcessId.None; var pong = ProcessId.None; Process.PreShutdown.Subscribe(_ => { kill(ping); kill(pong); }); // Start a process which simply writes the messages it receives to std-out var logger = spawn <string>("logger", x => Console.WriteLine(x)); // Ping process ping = spawn <string>("ping", msg => { tell(logger, msg); var res = readList <int>("arr"); var name = read("name", ""); var ind = read("count", 0); write("count", ind + 1); tell(pong, $"ping {name}-{ind}", TimeSpan.FromMilliseconds(100)); }); // Pong process pong = spawn <string>("pong", msg => { tell(logger, msg); var map = readMap <string>("map"); var name = read("name", ""); var ind = read("count", 0); write("count", ind + 1); tell(ping, $"pong {name}-{ind}", TimeSpan.FromMilliseconds(100)); }); // Trigger tell(ping, "start"); Console.ReadKey(); Process.shutdownAll(); }
public void RedisRegisterTest() { lock (sync) { shutdownAll(); Assert.True(Systems.Count == 0); // Let Language Ext know that Redis exists RedisCluster.register(); // Connect to the Redis cluster ProcessConfig.initialise("sys", "global", "redis-test", "localhost", "0"); string value = null; var pid = spawn <string>("reg-proc", msg => value = msg); var regid = register("woooo amazing", pid); Assert.True(regid == "/disp/reg/global-woooo amazing"); Thread.Sleep(200); tell(regid, "hello"); Thread.Sleep(200); Assert.True(value == "hello"); tell(find("woooo amazing"), "world"); Thread.Sleep(200); Assert.True(value == "world"); deregisterById(pid); Thread.Sleep(200); try { tell(find("woooo amazing"), "noooo"); } catch (Exception e) { Assert.True(e.Message.Contains("No processes in group")); } Thread.Sleep(200); Assert.True(value != "noooo"); } }
public static void RegisterTest() { try { shutdownAll(); // Let Language Ext know that Redis exists RedisCluster.register(); // Connect to the Redis cluster Cluster.connect("redis", "redis-test", "localhost", "0", "global"); string value = null; var pid = spawn <string>("reg-proc", msg => value = msg); var regid = register <string>("woooo amazing", pid); Thread.Sleep(10); var kids = children(Registered); Debug.Assert(kids.Count() == 1); Debug.Assert(kids["woooo amazing"].Path == "/registered/woooo amazing"); tell(regid, "hello"); Thread.Sleep(10); Debug.Assert(value == "hello"); tell(find("woooo amazing"), "world"); Thread.Sleep(10); Debug.Assert(value == "world"); Thread.Sleep(10); deregister("woooo amazing"); Thread.Sleep(10); kids = children(Registered); Debug.Assert(kids.Count() == 0); } finally { Cluster.disconnect(); } }
static void Main(string[] args) { // Remove this to get on-screen logging ProcessSystemLog.Subscribe(Console.WriteLine); // Let Language Ext know that Redis exists RedisCluster.register(); // Connect to the Redis cluster Cluster.connect("redis", "redis-session-test", "localhost:6379", "0", "global"); var ping = ProcessId.None; var pong = ProcessId.None; // Start a process which simply writes the messages it receives to std-out var logger = spawn <string>("logger", Console.WriteLine); sessionStart("xyz", 20 * seconds); // Ping process ping = spawn <string>("ping", msg => { tell(logger, msg); var txt = hasSession() ? sessionId().ToString() : "expired"; tell(pong, "ping-" + txt, TimeSpan.FromMilliseconds(1000)); }); // Pong process pong = spawn <string>("pong", msg => { tell(logger, msg); var txt = hasSession() ? sessionId().ToString() : "expired"; tell(ping, "pong-" + txt, TimeSpan.FromMilliseconds(1000)); }); // Trigger tell(pong, "start"); Console.ReadKey(); }
static void Main(string[] args) { // Log what's going on // ProcessLog.Subscribe(Console.WriteLine); // Let Language Ext know that Redis exists RedisCluster.register(); // Connect to the Redis cluster ProcessConfig.initialise("sys", "global", "redis-subscribe-test", "localhost", "0"); var pid = ProcessId.Top["redis-publish-test"]["user"]["redis-pubsub-random-test"]; // Listen to the published results coming back from the Redis channel subscribe <int>(pid, Console.WriteLine); Console.ReadKey(); }
static void Test1() { ProcessId pong = ProcessId.None; ProcessId ping = ProcessId.None; // Let Language Ext know that Redis exists RedisCluster.register(); // Connect to the Redis cluster ProcessConfig.initialise("sys", "global", "redis-test", "localhost", "0"); ping = spawn <string>( Name: "ping", Inbox: msg => { Console.WriteLine(msg); tell(pong, "pong", 100 * ms); }, Terminated: pid => Console.WriteLine(pid + " is pushing up the daisies"), Flags: ProcessFlags.PersistInbox ); pong = spawn <string>( Name: "pong", Inbox: msg => { Console.WriteLine(msg); tell(ping, "ping", 100 * ms); }, Terminated: pid => Console.WriteLine(pid + " is pushing up the daisies"), Flags: ProcessFlags.PersistInbox ); watch(ping, pong); watch(pong, ping); tell(pong, "Running"); Console.WriteLine("Press key to kill ping"); Console.ReadKey(); kill(ping); Console.WriteLine("Press key to exit"); Console.ReadKey(); }
//public static void RegisteredAskReply() //{ // shutdownAll(); // ProcessConfig.initialise(); // var helloServer = spawn<string>("hello-server", msg => // { // reply("Hello, " + msg); // }); // var hi = register<string>("hi", helloServer); // var response = ask<string>(find("hi"), "Paul"); // Debug.Assert(response == "Hello, Paul"); //} public static void AskReply() { shutdownAll(); // Let Language Ext know that Redis exists RedisCluster.register(); // Connect to the Redis cluster ProcessConfig.initialise("sys", "global", "redis-test", "localhost", "0"); var helloServer = spawn <string>("hello-server", msg => { reply("Hello, " + msg); }, ProcessFlags.PersistInbox); var response = ask <string>(helloServer, "Paul"); Debug.Assert(response == "Hello, Paul"); }
public void RedisRegisterTest() { shutdownAll(); // Let Language Ext know that Redis exists RedisCluster.register(); // Connect to the Redis cluster Cluster.connect("redis", "redis-test", "localhost", "0", "global"); string value = null; var pid = spawn <string>("reg-proc", msg => value = msg); var regid = register("woooo amazing", pid); Assert.True(regid == "/disp/reg/global-woooo amazing"); Thread.Sleep(100); tell(regid, "hello"); Thread.Sleep(100); Assert.True(value == "hello"); tell(find("woooo amazing"), "world"); Thread.Sleep(100); Assert.True(value == "world"); deregisterById(pid); Thread.Sleep(100); tell(find("woooo amazing"), "noooo"); Thread.Sleep(100); Assert.True(value != "noooo"); }
// // Launch a process that adds the int sent in a message to its state // Then calls itself after a second to do the same again. The state value gradually // increases. // // If you stop the sample and restart you'll notice the state has been persisted // static void Main(string[] args) { // Log what's going on // ProcessLog.Subscribe(Console.WriteLine); // Let Language Ext know that Redis exists RedisCluster.register(); // Connect to the Redis cluster Cluster.connect("redis", "redis-test", "localhost", "0"); // Spawn the process var pid = spawn <int, int>("redis-state-sample", Setup, Inbox, ProcessFlags.PersistState); // Subscribe locally to the state changes observeState <int>(pid).Subscribe(Console.WriteLine); // Start it off by sending the first message tell(pid, 1); Console.ReadKey(); }
// // This sample sends messages published by a Language Ext process (by calling 'publish') // to a Redis channel. We then subscribe to the messages coming back where we push them // out to the console. // static void Main(string[] args) { // Log what's going on // ProcessLog.Subscribe(Console.WriteLine); // Let Language Ext know that Redis exists RedisCluster.register(); // Connect to the Redis cluster Cluster.connect("redis", "redis-test", "localhost:6379", "0"); // Launch a process that publishes a random number as fast as possible var pid = spawn <Random, int>("redis-pubsub-random-test", Setup, Inbox, ProcessFlags.RemotePublish); // Listen to the published results coming back from the Redis channel subscribe <int>(pid, Console.WriteLine); // Start it off by sending the first message tell(pid, 0); Console.ReadKey(); }