Comments (5)
publishing a base class doesn't really make sense. you should publish concrete implementations and subscribe to interfaces.
from chinchilla.
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.
IIRC the implementation here was done with the idea of just subscribing to interfaces, not for message versioning. The integration tests are here:
Given the current implementation you could:
- Publish OtherMessage and OtherMessage2 to the same exchange
- Subscribe to
IOtherMessage
on a queue bound to that exchange
You'd need to configure the subscriptions and publishers to do this.
from chinchilla.
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.
@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)
- A custom requst/reply topology builder. HOT 3
- Does chinchilla support a consumer cancellation notification? HOT 2
- RabbitMQ.Client new version (3.4.0) HOT 6
- Receive disconnect event if RabbitMQ Server is stopped or client lost network connectivity HOT 4
- TaskDeliveryStrategy number of workers HOT 2
- Frequent Invocation of CreatePublisher HOT 1
- How to implement message TTL to queue or per message HOT 4
- Is there a way to determine if the connection is still opened HOT 3
- Connection HOT 1
- RabbitMQ client version 3.4.4 compatibility HOT 4
- Chincilla generating exception when using RabbitMQ client version 3.5 HOT 4
- Connect to a cluster
- Prefetch count issue HOT 3
- Send/Receive pattern HOT 3
- Topology Configurable Requester HOT 6
- How to create topology using fanout HOT 1
- Configure Chinchilla to connect to RMQ Cluster HOT 3
- Support .NET Standard HOT 4
- Build number is wrong and Nuget push doesn't detect packages
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chinchilla.