English 中文(简体)
网上安全分类
原标题:Thread Safe Publish Subscribe in .Net

我建立了一套简单的接口和一个类别,使我能够以普通字典出版项目的增量和清除量。 登记员在签字时收到全部名单,此后只得到改动。

尽管我的解决办法是行之有效的,但我正在寻找一些标准稍微提高的东西,而这种标准几乎没有本土。 你们是否有任何建议?

www.un.org/Depts/DGACM/index_spanish.htm 关于我迄今发现的情况的说明:

我一直在研究Microsoft的追溯延伸。 根据Joon Skeet的“LINQ to Rx: second mys” ***,他说,“观察者一旦签字,即可按顺序(在不同的路面上,在违约时)公布所有材料。 单独要求登记在多个时间序列上的可观测性 这种说法像基本想法一样,但我找不到任何具体的例子,我并不真正相信“目标”或“AsyncSubject”的表面安全。

www.un.org/Depts/DGACM/index_spanish.htm 关于我的本土解决办法的说明:

提供给用户的结构类似:

/// <summary>
/// Interface for a set of changes that are being published.
/// </summary>
/// <typeparam name="TKey"></typeparam>
/// <typeparam name="TItem"></typeparam>
public interface IPublication<TKey, TItem>
{
    /// <summary>
    /// Version of the list.
    /// </summary>
    long Version { get; }
    /// <summary>
    /// Items that were added or updated.
    /// </summary>
    IEnumerable<TItem> ChangedItems { get; }
    /// <summary>
    /// Keys to items that were removed.
    /// </summary>
    IEnumerable<TKey> RemovedKeys { get; }
}

用户本身必须实施这一接口:

/// <summary>
/// Interface for a subscriber that will receive IPublication{TKey, TItem} deliveries from a publisher.
/// </summary>
/// <typeparam name="TKey"></typeparam>
/// <typeparam name="TItem"></typeparam>
public interface ISubscribe<TKey, TItem>
{
    void Deliver(IPublication<TKey, TItem> pub);
}

当然,我的普通字典出版商有这一方法:

/// <summary>
/// Adds the give subscriber to the list of subscribers and immediately publishes the
/// dictionary contents to the new subscriber. The return value may be disposed when
/// the subscriber wishes to terminate it s subscription.
/// </summary>
/// <param name="subscriber"></param>
/// <returns></returns>
public IDisposable Subscribe(ISubscribe<TKey, TItem> subscriber);

[1] https://codeblog.jonskeet.uk/2010/01/19/linq-to-rx-second-impressions/

最佳回答

This is not really an answer but tedious to put into the comments so putting it here... Not sure why are you looking at a standard out of box solution when your custom solution is easy to build and will work? Events are the simplest (and standard) way of achieving publisher-subscriber model but they are not thread-safe and also suffer from tight coupling between subscriber and publisher. MS patterns & practice group had published WCF based pattern but I think that you are looking for a fast in-process kind of code. Similarly, many other standard publish-subscribe solutions will be targeting application integration (ESB). In case you didn t find any alternatives and decided to go with your custom solution then you mar refer this artcile that describes issues in implementing this design pattern.

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签