本文整理汇总了C#中IMessage.GetPayload方法的典型用法代码示例。如果您正苦于以下问题:C# IMessage.GetPayload方法的具体用法?C# IMessage.GetPayload怎么用?C# IMessage.GetPayload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMessage
的用法示例。
在下文中一共展示了IMessage.GetPayload方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Handler
private async Task<IActorResult> Handler(IMessage message)
{
var cityWeather = message.GetPayload<CityWeatherMessage>();
var correlationId = new Guid(message.CorrelationId.GetString());
var cityName = cityWeather.Weather.CityName;
var temperature = cityWeather.Weather.Temperature;
if (temperature != null)
{
await GetReduceDocument(correlationId);
await UpdateHighestTemperature(correlationId, temperature, cityName);
await UpdateLowestTemperature(correlationId, temperature, cityName);
}
var result = await IncrementMessageCount(correlationId);
if (result.MessagesProcessed % 100 == 0)
{
WriteLine($"Done {result.MessagesProcessed} out of {cityWeather.TotalCityCount}");
}
if (result.MessagesProcessed == cityWeather.TotalCityCount)
{
return CreateAggregatedWeatherMessage(result);
}
return null;
}
示例2: StartProcess
private async Task<IActorResult> StartProcess(IMessage message)
{
var hello = message.GetPayload<HelloMessage>();
//System.Console.WriteLine(hello.Greeting);
//return await Task.Delay(0)
// .ContinueWith(_ => Message.Create(new EhlloMessage
// {
// Ehllo = new string(hello.Greeting.Reverse().ToArray())
// },
// EhlloMessage.MessageIdentity))
// .ConfigureAwait(false);
//throw new Exception("Bla!");
//Thread.Sleep(50000);
var reversedString = new string(hello.Greeting.Reverse().ToArray());
//WriteLine(reversedString);
return new ActorResult(Message.Create(new EhlloMessage
{
Ehllo = reversedString
},
EhlloMessage.MessageIdentity));
}
示例3: AsyncProcess
private async Task<IActorResult> AsyncProcess(IMessage messageIn)
{
var error = messageIn.GetPayload<AsyncExceptionMessage>();
await Task.Delay(error.Delay).ContinueWith(_ => { throw new Exception(error.ErrorMessage); }).ConfigureAwait(false);
return null;
}
示例4: HandleException
private Task<IActorResult> HandleException(IMessage message)
{
var payload = message.GetPayload<ExceptionMessage>();
Console.WriteLine(payload.Exception.ToString());
return null;
}
示例5: StartProcess
private async Task<IActorResult> StartProcess(IMessage message)
{
var ehllo = message.GetPayload<EhlloMessage>();
var messageOut = Message.Create(new GroupCharsResponseMessage
{
Groups = ehllo.Ehllo.GroupBy(c => c).Select(g => new GroupInfo {Char = g.Key, Count = g.Count()}),
Text = ehllo.Ehllo
},
GroupCharsResponseMessage.MessageIdentity);
return new ActorResult(messageOut);
}
示例6: Handler
private async Task<IActorResult> Handler(IMessage message)
{
var request = message.GetPayload<RequestWeatherHighlightsMessage>();
var totalCount = request.Cities.Count();
var response = new ActorResult(request
.Cities
.Select(city => Message.Create(new RequestCityWeatherMessage
{
CityName = city,
TotalCityCount = totalCount
})).ToArray());
return response;
}
示例7: SetResult
internal void SetResult(IMessage message)
{
expirableItem?.ExpireNow();
if (Unsafe.Equals(message.Identity, ExceptionMessage.MessageIdentity))
{
var error = message.GetPayload<ExceptionMessage>().Exception;
result.SetException(error);
}
else
{
result.SetResult(message);
}
}
示例8: Handler
private async Task<IActorResult> Handler(IMessage message)
{
var request = message.GetPayload<LogCityWeatherMessage>();
var cityWeather = new CityWeatherHistory
{
CorrelationId = new Guid(message.CorrelationId.GetString()),
Weather = new Weather
{
CityName = request.Weather.CityName,
Temperature = request.Weather.Temperature
}
};
db.GetCollection<CityWeatherHistory>(CityWeatherHistory.Collection)
.InsertOneAsync(cityWeather);
return null;
}
示例9: Handler
private async Task<IActorResult> Handler(IMessage message)
{
var request = message.GetPayload<RequestCityWeatherMessage>();
var weather = await GetCityWeather(request.CityName);
var cityWeather = new CityWeather
{
CityName = request.CityName,
Temperature = weather?.Main?.Temp
};
var response = Message.Create(new CityWeatherMessage
{
Weather = cityWeather,
TotalCityCount = request.TotalCityCount
});
var log = Message.Create(new LogCityWeatherMessage
{
Weather = cityWeather
});
return new ActorResult(response, log);
}
示例10: OnWriteReceived
private void OnWriteReceived(IMessage message)
{
var payload = message.GetPayload<LeaseWriteMessage>();
var ballot = new Ballot(new DateTime(payload.Ballot.Timestamp, DateTimeKind.Utc),
payload.Ballot.MessageNumber,
payload.Ballot.Identity);
IMessage response;
if (writeBallot > ballot || readBallot > ballot)
{
LogNackWrite(ballot);
response = Message.Create(new LeaseNackWriteMessage
{
Ballot = payload.Ballot,
SenderUri = synodConfig.LocalNode.Uri.ToSocketAddress()
},
LeaseNackWriteMessage.MessageIdentity);
}
else
{
LogAckWrite(ballot);
writeBallot = ballot;
var ownerEndpoint = new OwnerEndpoint
{
UnicastUri = new Uri(payload.Lease.OwnerEndpoint.UnicastUri),
MulticastUri = new Uri(payload.Lease.OwnerEndpoint.MulticastUri)
};
lease = new Lease(payload.Lease.Identity, ownerEndpoint, new DateTime(payload.Lease.ExpiresAt, DateTimeKind.Utc));
response = Message.Create(new LeaseAckWriteMessage
{
Ballot = payload.Ballot,
SenderUri = synodConfig.LocalNode.Uri.ToSocketAddress()
},
LeaseAckWriteMessage.MessageIdentity);
}
intercomMessageHub.Send(response, payload.SenderIdentity);
}
示例11: IsPong
private bool IsPong(IMessage message)
{
if (Unsafe.Equals(PongMessage.MessageIdentity, message.Identity))
{
var payload = message.GetPayload<PongMessage>();
return !ThisNodeSocket(payload.SocketIdentity);
}
return false;
}
示例12: RegisterExternalRoutes
private bool RegisterExternalRoutes(IMessage message, ISocket scaleOutBackend)
{
var shouldHandle = IsExternalRouteRegistration(message);
if (shouldHandle)
{
var payload = message.GetPayload<RegisterExternalMessageRouteMessage>();
var handlerSocketIdentifier = new SocketIdentifier(payload.SocketIdentity);
var uri = new Uri(payload.Uri);
foreach (var registration in payload.MessageContracts)
{
try
{
var messageHandlerIdentifier = new MessageIdentifier(registration.Version, registration.Identity);
externalRoutingTable.AddMessageRoute(messageHandlerIdentifier, handlerSocketIdentifier, uri);
scaleOutBackend.Connect(uri);
}
catch (Exception err)
{
logger.Error(err);
}
}
}
return shouldHandle;
}
示例13: RegisterInternalMessageRoutes
private bool RegisterInternalMessageRoutes(IMessage message)
{
var shouldHandle = IsInternalMessageRoutingRegistration(message);
if (shouldHandle)
{
var payload = message.GetPayload<RegisterInternalMessageRouteMessage>();
var handlerSocketIdentifier = new SocketIdentifier(payload.SocketIdentity);
var handlers = UpdateLocalRoutingTable(payload, handlerSocketIdentifier);
clusterMonitor.RegisterSelf(handlers);
}
return shouldHandle;
}
示例14: UnregisterRoute
private bool UnregisterRoute(IMessage message, ISocket scaleOutBackend)
{
var shouldHandle = IsUnregisterRouting(message);
if (shouldHandle)
{
var payload = message.GetPayload<UnregisterNodeMessageRouteMessage>();
externalRoutingTable.RemoveNodeRoute(new SocketIdentifier(payload.SocketIdentity));
try
{
scaleOutBackend.Disconnect(new Uri(payload.Uri));
}
catch (EndpointNotFoundException)
{
}
}
return shouldHandle;
}
示例15: DiscoverMessageRoute
private bool DiscoverMessageRoute(IMessage message)
{
var shouldHandle = IsDiscoverMessageRouteRequest(message);
if (shouldHandle)
{
var messageContract = message.GetPayload<DiscoverMessageRouteMessage>().MessageContract;
var messageIdentifier = new MessageIdentifier(messageContract.Version, messageContract.Identity);
if (internalRoutingTable.CanRouteMessage(messageIdentifier))
{
clusterMonitor.RegisterSelf(new [] { messageIdentifier});
}
}
return shouldHandle;
}