Publish subscribe

149 views
Skip to first unread message

everton elliott

unread,
May 30, 2013, 5:16:12 AM5/30/13
to sider-l...@googlegroups.com
Hi,

Can any one provide a working example of Sider 0.9 and c# doing publish subscribe?

Chakrit Wichian

unread,
May 31, 2013, 1:44:15 AM5/31/13
to sider-l...@googlegroups.com
Hi Elliot.

I've put together a gist that you can check out here:

It basically spawns two asynchronous task, one PUBLISH-ing
stuff into it and the other just SUBSCRIBE-ing to the channel
and print received messages to the console.

You will need:
  • Standard Console Project
  • Sider package installed via NuGet
  • Rx-Core package installed via NuGet

Also the redis documentation will explain the parameters used.

It uses the Reactive stuff internally so you might be able to
understand it better if you read up on the thing first.

Hope this helps.

On Thursday, May 30, 2013 at 4:16 PM, everton elliott wrote:

Hi,

Can any one provide a working example of Sider 0.9 and c# doing publish subscribe?

--
You received this message because you are subscribed to the Google Groups "Sider + Lemonade" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sider-lemonad...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

everton elliott

unread,
May 31, 2013, 5:32:31 AM5/31/13
to sider-l...@googlegroups.com
Hi,

Sorry about buzzing on twitter.
I want to write a c# stored procedure to be used with SQLserver 2008r2.
This means can not be .net 4.0.


c:\Csharp>C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe /r:Sider.dll,System.Reactive.Core.dll sider_pubsubtest.cs
Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.5420
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.

sider_pubsubtest.cs(5,24): error CS0234: The type or namespace name 'Tasks' does not exist in the namespace
'System.Threading' (are you missing an assembly reference?)

Chakrit Wichian

unread,
May 31, 2013, 5:34:32 AM5/31/13
to sider-l...@googlegroups.com
I think you can rewrite the example I gave you using `new Thread` instead of `Task`.

Task is a .NET 4.0 thing IIRC. But both Sider and Reactive.Core probably don't need them.

I don't have access to .NET 3.5 environment so can't test or code for you, sorry.

everton elliott

unread,
May 31, 2013, 6:55:02 AM5/31/13
to sider-l...@googlegroups.com
Hi,

Path is set to .net v3.5
Using threading rather than tasks.
Seems that Sider required .net 2 ?

Tried .net 2, can not use 'var' when creating a new object.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Sider;

namespace DummyConsole
{
class Program
{
static void Main(string[] args)
{
var pump = new Thread(Pump);
var drain = new Thread(Drain);

pump.Start();
drain.Start();
// Spin for a while waiting for the started thread to become
// alive:
while (!pump.IsAlive);

// wait for pump to end...
pump.Join();
}

private static void Pump()
{
var client = new RedisClient();
while (true) {
client.Publish("HELLO", DateTime.Now.ToString());
Thread.Sleep(1) ;
}
}

private static void Drain()
{
var client = new RedisClient();
var channel = client.Subscribe("HELLO");
channel.Subscribe((m) => Console.WriteLine("SUBSCRIBE BODY ->"+m.Body));
}
}
}

c:\Csharp>csc /r:Sider.dll,System.Reactive.Core.dll sider_pubsubtest.cs


Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.5420
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.

Sider.dll: warning CS1684: Reference to type 'System.Func`2' claims it is defined in
'c:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll', but it could not be found
Sider.dll: warning CS1684: Reference to type 'System.IObservable`1' claims it is defined in
'c:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll', but it could not be found
sider_pubsubtest.cs(29,20): error CS1729: 'Sider.RedisClient' does not contain a constructor that takes '0' arguments
Sider.dll: (Location of symbol related to previous error)
sider_pubsubtest.cs(38,20): error CS1729: 'Sider.RedisClient' does not contain a constructor that takes '0' arguments
Sider.dll: (Location of symbol related to previous error)
System.Reactive.Core.dll: warning CS1684: Reference to type 'System.IObservable`1' claims it is defined in
'c:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll', but it could not be found
Sider.dll: warning CS1684: Reference to type 'System.Tuple`2' claims it is defined in
'c:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll', but it could not be found
Sider.dll: warning CS1684: Reference to type 'System.Tuple`3' claims it is defined in
'c:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll', but it could not be found
Sider.dll: warning CS1684: Reference to type 'System.Tuple`4' claims it is defined in
'c:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll', but it could not be found
Sider.dll: warning CS1684: Reference to type 'System.Tuple`5' claims it is defined in
'c:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll', but it could not be found
sider_pubsubtest.cs(39,21): error CS0570: 'System.ObservableExtensions.Subscribe<T>()' is not supported by the language
System.Reactive.Core.dll: (Location of symbol related to previous error)
sider_pubsubtest.cs(39,21): error CS0570: 'Subscribe' is not supported by the language
Sider.dll: (Location of symbol related to previous error)

Chakrit Wichian

unread,
May 31, 2013, 6:57:33 AM5/31/13
to sider-l...@googlegroups.com
Not sure, please try compiling from source.

If that fails, then I guess either Sider simply won't work on 3.5.

Pull Request for a port welcome though.

everton elliott

unread,
May 31, 2013, 7:08:50 AM5/31/13
to sider-l...@googlegroups.com
Only seems to compile with csc.exe .NET 4.

using System;
using System.Collections.Generic;

everton elliott

unread,
May 31, 2013, 8:31:34 AM5/31/13
to sider-l...@googlegroups.com
Hi,

Trying to write the 'var' to use explicit objects
How do rewrite : IObservable<Message<string> channel = client.Subscribe("HELLO");

private static void Drain()
{
RedisClient<string> client = new RedisClient();
IObservable<Message<string> channel = client.Subscribe("HELLO");

everton elliott

unread,
May 31, 2013, 9:29:59 AM5/31/13
to sider-l...@googlegroups.com

Ok got ride of the 'Var', but still can not compile.
Will make a request to see if port can be down to .Net 3.5.
This compiles on and runs on .NET 4.0 but not .NOT 3.5

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using Sider;

namespace DummyConsole
{
class Program
{
static void Main(string[] args)
{

Thread pump = new Thread(Pump);
Thread drain = new Thread(Drain);



pump.Start();
drain.Start();
// Spin for a while waiting for the started thread to become
// alive:
while (!pump.IsAlive);

// wait for pump to end...
pump.Join();
}

private static void Pump()
{

RedisClient<string> client = new RedisClient();

while (true) {
client.Publish("HELLO", DateTime.Now.ToString());
Thread.Sleep(1) ;
}
}

private static void Drain()
{
RedisClient<string> client = new RedisClient();

//var channel = client.Subscribe("HELLO");
IObservable<Sider.Message<string>> channel = client.Subscribe("HELLO");
Type types = GetDeclaredType(channel) ;
Console.WriteLine(types.Name) ;
Console.ReadKey();


channel.Subscribe((m) => Console.WriteLine("SUBSCRIBE BODY ->"+m.Body));
}

public static Type GetDeclaredType<T>(T obj)
{
return typeof(T);
}

}
}

Mauricio Tabares

unread,
Aug 30, 2014, 3:50:35 PM8/30/14
to sider-l...@googlegroups.com
Hi, i'm getting the following error in 4.0

Reply all
Reply to author
Forward
0 new messages