MessageContextProviderBase1

MessageContextProviderBase1

本文介绍了RawRabbit 序列化问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 RawRabbit 实现一个图像处理服务,该服务将接收要处理的图像并将提取的信息返回到不同的队列.删除所有不必要的代码后,我意识到我面临的问题是当我从订阅委托中调用发布时.

I'm trying to implement an image processing service using RawRabbit that is going to receive images to be processed and will return the extracted information to a different queue. After removing all the unnecessary code I realized that the problem I am facing is when I call publish from within subscribe delegate.

有谁知道我做错了什么?我的应用程序基于 .Net core 2.0

Does anyone know what I am doing wrong? My application is based on .Net core 2.0

下面是我订阅的方法.

public async Task StartListening()
    {
        try
        {
            _log.InfoFormat("Preparing to subscribe to queue messages");

            LoadConfiguration();

            CreateBusClient();
            _log.DebugFormat("BusClient created, calling subscribe");

            _client.SubscribeAsync<string>((msgStr, context) =>
            {

                _client.PublishAsync("test", default(Guid), cfg => cfg.WithExchange(exc => exc.WithName("face_process_exchange").WithType(ExchangeType.Direct)).WithRoutingKey("face_process_response"));
                return Task.FromResult(true);

            }, cfg => cfg.WithExchange(exc => exc.WithName(_configuration.Exchange).WithType(ExchangeType.Direct)).
                        WithRoutingKey(_configuration.RoutingKeyToListen).
                        WithQueue(q => q.WithName(_configuration.QueueToListen)).
                        WithSubscriberId(""));

            _log.Info("Subscribed to queue");
        }
        catch(Exception e)
        {
            _log.ErrorFormat("Failed to subscribe to queue: {0}", e.ToString());
        }
    }

这是我创建 BusClient 的方法;

And here is the method where I create the BusClient;

private void CreateBusClient()
    {
        var busConfig = new RawRabbitConfiguration
        {
            Username = _configuration.ConnectionUsername,
            Password = _configuration.ConnectionPassword,
            Port = _configuration.ConnectionPort,
            VirtualHost = "/",
            Hostnames = { _configuration.Hostname },
            RouteWithGlobalId = false
        };

        _log.DebugFormat("Calling BusClientFactory.CreateDefault for _configuration read as: {0}", _configuration.ToString());

        var addCfg = new Action<IServiceCollection>(s => s.AddSingleton(p => busConfig));
        var serviceProvider = new ServiceCollection().AddRawRabbit<AdvancedMessageContext>(null, addCfg).BuildServiceProvider();

        var cs = serviceProvider.GetService<IBusClient<AdvancedMessageContext>>();
        _client = new RawRabbit.vNext.Disposable.BusClient<AdvancedMessageContext>(cs);
    }

```

问题是在调用 PublishAsync 时总是出现以下异常.

The problem is that I always get the following exception when PublishAsync is called.

System.Runtime.Serialization.SerializationException:此平台不支持序列化委托.在 System.MulticastDelegate.GetObjectData(SerializationInfo 信息,StreamingContext 上下文)在 Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeISerializable(JsonWriter writer, ISerializable value, JsonISerializableContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)在 Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)在 Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)在 Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)在 RawRabbit.Context.Provider.MessageContextProviderBase1.SerializeContext(TMessageContext messageContext)在 RawRabbit.Context.Provider.MessageContextProviderBase1.GetMessageContext(Guid& globalMessageId)在 RawRabbit.Operations.Publisher1.PublishAsync[TMessage](TMessage 消息,Guid globalMessageId,PublishConfiguration 配置)在 RawRabbit.Common.BaseBusClient1.PublishAsync[T](T message, Guid globalMessageId, Action1 配置)在 RawRabbit.vNext.Disposable.BusClient1.PublishAsync[T](T message, Guid globalMessageId, Action`1 配置)在 SimpleID.FaceProcessing.Services.Implementation.RawRabbitQueueService.b__11_0(String msgStr, AdvancedMessageContext context)

System.Runtime.Serialization.SerializationException: Serializing delegates is not supported on this platform. at System.MulticastDelegate.GetObjectData(SerializationInfo info, StreamingContext context) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeISerializable(JsonWriter writer, ISerializable value, JsonISerializableContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType) at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType) at RawRabbit.Context.Provider.MessageContextProviderBase1.SerializeContext(TMessageContext messageContext) at RawRabbit.Context.Provider.MessageContextProviderBase1.GetMessageContext(Guid& globalMessageId) at RawRabbit.Operations.Publisher1.PublishAsync[TMessage](TMessage message, Guid globalMessageId, PublishConfiguration config) at RawRabbit.Common.BaseBusClient1.PublishAsync[T](T message, Guid globalMessageId, Action1 configuration) at RawRabbit.vNext.Disposable.BusClient1.PublishAsync[T](T message, Guid globalMessageId, Action`1 configuration) at SimpleID.FaceProcessing.Services.Implementation.RawRabbitQueueService.b__11_0(String msgStr, AdvancedMessageContext context)

推荐答案

此问题作为 Github 问题发布在 RawRabbit 存储库上并由存储库所有者 (@pardahlman) 回答:

This question was posted as a Github issue on the RawRabbit repo and answered by the repo owner (@pardahlman):

https://github.com/pardahlman/RawRabbit/issues/286

我认为这是 AdvancedMessageContext 的问题.这是可以修复,但需要注册自定义内部服务.在我进入细节之前:你认为它会是吗?是否可以迁移到 2.0(目前在 rc1 中)?这不再是一个该客户的问题.

这篇关于RawRabbit 序列化问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 17:07