1
안녕하세요, MassBransit의 다음과 같은 문제를 해결하는 방법을 알고 계십니다. 고객은 요청 및 응답을 받았지만 응답은 클라이언트로 반환되지 않습니다. 요청. 방법. I는 ASP NET 웹 API 프로젝트를 생성하고 난 IRequestClient 인터페이스 요청/응답 통신을 구현 : I가 Autofac에서 모듈로 serviceBus 구성을 만들었MassTransit은 소비자로부터 응답을 받았습니다
public class RequestResponseCommandProvider<TRequest, TResponse>
: IRequestResponseCommandProvider<TRequest, TResponse>
where TRequest : class, ICommandQueueName
where TResponse : class
{
private readonly IBusControl _bus;
private readonly string _hostUri;
public RequestResponseCommandProvider(IBusControl bus,
string hostUri)
{
_bus = bus;
_hostUri = hostUri;
}
public TResponse RequestResponseCommand(TRequest command)
{
_bus.Start();
var serviceAddress = new Uri(_hostUri + command.QueueName);
IRequestClient<TRequest, TResponse> client =
_bus.CreateRequestClient<TRequest, TResponse>(serviceAddress, TimeSpan.FromSeconds(10));
return client.Request(command).Result; //there should back response
}
}
:
public class BusModule : Autofac.Module
{
private readonly string _hostUri;
IEnumerable<IConfigurableConsumer> _consumers;
public BusModule(string hostUri, IEnumerable<IConfigurableConsumer> consumers)
{
_hostUri = hostUri;
_consumers = consumers;
}
protected override void Load(ContainerBuilder builder)
{
builder.RegisterAssemblyTypes(AppDomain.CurrentDomain.GetAssemblies());
builder.Register(r => Bus.Factory.CreateUsingRabbitMq(sfc =>
{
var host = sfc.Host(new Uri(_hostUri), h =>
{
h.Username("guest");
h.Password("guest");
});
if (_consumers != null)
{
foreach (var consumer in _consumers)
{
consumer.Configure(sfc);
}
}
}))
.As<IBus>()
.As<IBusControl>()
.SingleInstance();
builder.RegisterType<RecieveObserver>()
.As<IReceiveObserver>();
}
}
소비자가 추가 건설자. 내가 RabbitMQ에서 모든 메시지를 큐를 검사 할 때 이것처럼 보이는
public class TestLayer : ITestLayer
{
private readonly IRequestResponseCommandProvider<IAddTestCommand, ResponseCommand> _provider;
public TestLayer(
IRequestResponseCommandProvider<IAddTestCommand, ResponseCommand> provider)
{
_provider = provider;
}
public ServiceResult CreateTest(TestRecord record)
{
ServiceResult result;
try
{
var tmp = _provider.RequestResponseCommand(new AddTestCommand() { Record = "d3d32" });
result = new ServiceResult();
}
catch (Exception ex)
{
result = new ServiceResult();
result.AddError($"Wystąpił problem podczas zapisu do bazy danych: {ex}");
}
return result;
}
}
: 제공자는 서비스에 주입 크리스 패터슨에 의해 RabbitMQ queue
내가 이미 본 샘플-RequestResponse하지만 난 문제 때이 의존성 주입을 사용하십시오. 난 내가 잘못 한 일 도움에 대한 감사합니다 ..이 코드가 포함되어 간단한 프로젝트 아직도 나던 작업을 찾을 수 있습니다 GitHub의 모든 저장소도있다 : My GitHub