Coder Social home page Coder Social logo

Comments (5)

jonnii avatar jonnii commented on August 20, 2024

publishing a base class doesn't really make sense. you should publish concrete implementations and subscribe to interfaces.

from chinchilla.

abrasat avatar abrasat commented on August 20, 2024

You are right, but it was just an example. Subscribing to interfaces does not work either, even with published concrete implementations derived from the interface.
The changed publisher code:

using (var bus = Depot.Connect("localhost"))
{
    while (running)
    {
        if (i % 2 == 0)
        {
            var pubMsg = new OtherMessage()
            {
                MsgId = i,
                DataI = i*2
            };
            bus.Publish(pubMsg);
        }
        else if (i % 2 == 1)
        {
            var pubMsg = new OtherMessage2()
            {
                MsgId = i,
                DataF = i*3.0f
            };
            bus.Publish(pubMsg);
        }
        i++;
        Thread.Sleep(1000);
    }
  }

The GetMessageTypeName() method from the SubscriptionFactory.cs file does not seem to handle interfaces. Why does it actually remove the "I" from the interface type name ?

    public string GetMessageTypeName(Type type)
    {
        var typeName = type.Name;

        if (!type.IsInterface)
        {
            return typeName;
        }

        if (!typeName.StartsWith("I"))
        {
            var message = string.Format(
                "Cannot use '{0}' as an interface message contract because the message type name doesn't start with 'I'",
                typeName);

            throw new NotSupportedException(message);
        }

        return typeName.Substring(1);
    }

from chinchilla.

jonnii avatar jonnii commented on August 20, 2024

IIRC the implementation here was done with the idea of just subscribing to interfaces, not for message versioning. The integration tests are here:

https://github.com/jonnii/chinchilla/blob/c73bc81197990111185c9dae081f72e6b29de439/src/Chinchilla.Integration/Features/SubscribeFeature.cs

Given the current implementation you could:

  1. Publish OtherMessage and OtherMessage2 to the same exchange
  2. Subscribe to IOtherMessage on a queue bound to that exchange

You'd need to configure the subscriptions and publishers to do this.

from chinchilla.

abrasat avatar abrasat commented on August 20, 2024

Thank you for the reply, I will look into that.
I was not thinking about message versioning, I just have different messages that all implement a base interface. This is a quite common scenario when doing messaging applications.
The integration tests that you mentioned work only because the name of the implementation class is the same as the name of the interface, just without the leading "I". I think this is a special case, and not a general approach for supporting subscriptions for interfaces.

from chinchilla.

jonnii avatar jonnii commented on August 20, 2024

@abrasat I'm actually not sure what would happen if you tried to puhblish an interface, it would probably work but you'd need to configure the exchange explicitly. That said you need to be careful in general when serializing interface types, regardless of whether or not you use this library, e.g. how would you serialize an IList<string>? It would depend on the implementation. Deserializing you have the same problem. It could be an array, it could be a List<string> it could be a HashSet<string>?

from chinchilla.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.