public void Publish(int streamIndex, ulong id, IList <Message> messages, DateTime creationTime) { var message = new ScaleoutMessage { Messages = messages, ServerCreationTime = creationTime, }; OnReceived(streamIndex, id, message); }
public void SingleMessageOnlyVerifyIds() { var store = new ScaleoutStore(10); var message = new ScaleoutMessage(); store.Add(new ScaleoutMapping(10ul, message)); Assert.Equal(10ul, store.MinMappingId); Assert.Equal(10ul, store.MaxMapping.Id); }
protected override Task Send(int streamIndex, IList <Message> messages) { var message = new ScaleoutMessage(messages); OnReceived(streamIndex, _id, message); _id++; return(TaskAsyncHelper.Empty); }
public static NetMQMessage FromBytes(byte[] bytes) { using (var r = new BinaryReader(new MemoryStream(bytes))) { long messageId = r.ReadInt64(); byte[] messageBytes = r.ReadBytes(bytes.Length - 8); ScaleoutMessage scaleoutMessage = ScaleoutMessage.FromBytes(messageBytes); return(new NetMQMessage(messageId, scaleoutMessage)); } }
public static Stream ToStream(IList <Message> messages) { if (messages == null) { throw new ArgumentNullException("messages"); } var scaleoutMessage = new ScaleoutMessage(messages); return(new MemoryStream(scaleoutMessage.ToBytes())); }
protected override Task Send(int streamIndex, IList <Message> messages) { var scaleoutMessage = new ScaleoutMessage(messages); var bytes = scaleoutMessage.ToBytes(); //var stream = ServiceBusMessage.ToStream(messages); TraceMessages(messages, "Sending"); return(_connectionContext.Publish(streamIndex, bytes)); }
public static byte[] ToBytes(IList <Message> messages) { if (messages == null) { throw new ArgumentNullException("messages"); } var message = new ScaleoutMessage(messages); return(message.ToBytes()); }
// Send messages from the server to the backplane protected override Task Send(int streamIndex, IList <Message> messages) { return(Task.Factory.StartNew(() => { var bytes = new ScaleoutMessage(messages).ToBytes(); var filePath = BasePath + "\\" + DateTime.Now.Ticks + ".txt"; File.WriteAllBytes(filePath, bytes); })); }
public void AccurateMappingIds() { var store = new ScaleoutStore(10); var message1 = new ScaleoutMessage(); store.Add(new ScaleoutMapping(10ul, message1)); var message2 = new ScaleoutMessage(); store.Add(new ScaleoutMapping(15ul, message2)); Assert.Equal(10ul, store.MinMappingId); Assert.Equal(15ul, store.MaxMapping.Id); }
public void GettingMessagesWithCursorInbetweenOnElementRangeGetsAll() { var store = new ScaleoutStore(10); var message = new ScaleoutMessage(); store.Add(new ScaleoutMapping((ulong)1, message)); var result = store.GetMessagesByMappingId(2); Assert.Equal(0ul, result.FirstMessageId); Assert.Equal(0, result.Messages.Count); }
public void GettingMessagesWithSentinelCursorReturnsEverything() { var store = new ScaleoutStore(10); var message = new ScaleoutMessage(); store.Add(new ScaleoutMapping((ulong)0, message)); var result = store.GetMessagesByMappingId(UInt64.MaxValue); Assert.Equal(0ul, result.FirstMessageId); Assert.Equal(1, result.Messages.Count); }
public void GettingMessagesWithCursorBiggerThanMaxReturnsNothingIfNewer() { var store = new ScaleoutStore(10); for (int i = 0; i < 5; i++) { var message = new ScaleoutMessage(); store.Add(new ScaleoutMapping((ulong)i, message)); } var result = store.GetMessagesByMappingId(6); Assert.Equal(0, result.Messages.Count); }
public static byte[] ToBytes(IList <Message> messages) { using (var ms = new MemoryStream()) { var binaryWriter = new BinaryWriter(ms); var scaleoutMessage = new ScaleoutMessage(messages); var buffer = scaleoutMessage.ToBytes(); binaryWriter.Write(buffer.Length); binaryWriter.Write(buffer); return(ms.ToArray()); } }
public Task Send(IList <Message> messages) { if (messages == null || messages.Count == 0) { var tcs = new TaskCompletionSource <object>(); tcs.SetResult(null); return(tcs.Task); } _trace.TraceVerbose("{0}Sending payload with {1} messages(s)", _tracePrefix, messages.Count, _streamIndex); ScaleoutMessage message = new ScaleoutMessage(messages); return(_hubProxy.Invoke(BackplaneConstants.BroadcastNotification, message.ToBytes())); }
public static CouchbaseMessage FromMessages(int streamIndex, IList <Message> messages) { if (messages == null) { throw new NullReferenceException("messages"); } var scaleoutMessage = new ScaleoutMessage(messages); return(new CouchbaseMessage { Id = DateTime.UtcNow.ToString(), StreamIndex = streamIndex, Data = scaleoutMessage.ToBytes() }); }
public void GettingMessagesWithCursorLowerThanMinReturnsAll() { var store = new ScaleoutStore(10); for (int i = 5; i < 10; i++) { var message = new ScaleoutMessage(); store.Add(new ScaleoutMapping((ulong)i, message)); } var result = store.GetMessagesByMappingId(4); Assert.Equal(0ul, result.FirstMessageId); Assert.Equal(5ul, store.MinMappingId); Assert.Equal(5, result.Messages.Count); }
protected override void OnReceived(int streamIndex, ulong id, ScaleoutMessage message) { string value = message.Messages[0].GetString(); if (!value.Contains("ServerCommandType")) { if (_delay != TimeSpan.Zero) { Thread.Sleep(_delay); } Console.WriteLine("{0}: OnReceived({1}, {2}, {3})", _serverName, streamIndex, id, value); } base.OnReceived(streamIndex, id, message); }
public void StartReceiving() { _hubProxy.On <byte[]>(BackplaneConstants.ReceiveNotification, m => { ulong id = BitConverter.ToUInt64(m.Take(8).ToArray(), 0); ScaleoutMessage message = ScaleoutMessage.FromBytes(m.Skip(8).ToArray()); foreach (Message msg in message.Messages) { msg.MappingId = id; } _trace.TraceVerbose("Payload {0} containing {1} message(s) received", id, message.Messages.Count); Received(id, message); }); }
public void AssertMessagesWithCursorForRange(int[] values, ulong targetId, ulong firstId, int count) { var store = new ScaleoutStore(10); var message = new ScaleoutMessage(); foreach (var v in values) { store.Add(new ScaleoutMapping((ulong)v, message)); } var result = store.GetMessagesByMappingId(targetId); Assert.Equal(firstId, result.FirstMessageId); Assert.Equal(count, result.Messages.Count); }
public void GettingMessagesWithCursorLowerThanMinReturnsAllEvenAfterMultipleOverwrites() { var store = new ScaleoutStore(10); for (int i = 0; i < 100; i++) { var message = new ScaleoutMessage(); store.Add(new ScaleoutMapping(((ulong)i + MappingIdBase), message)); } var result = store.GetMessagesByMappingId(MappingIdBase + 62); Assert.Equal(64ul, result.FirstMessageId); Assert.Equal(63ul + MappingIdBase, store.MinMappingId); Assert.Equal(8, result.Messages.Count); Assert.True(result.HasMoreData); }
public void Publish(int streamIndex, ScaleoutMessage message) { if (Received != null) { lock (this) { Received(this, new EventMessage { Id = (ulong)id, Message = message, StreamIndex = streamIndex }); id++; } } }
private void ProcOldMessages(CallContext cntx, SignalRMessageServiceProxy msgsvc) { var hsvc = new SignalRHostStateServiceProxy(); var host = hsvc.LoadEntityByNature(cntx, config.HostName, config.App.ID).SingleOrDefault(); if (host == null) { host = new SignalRHostState { HostName = config.HostName, ApplicationID = config.App.ID, LastMsgId = 0 }; var x = hsvc.AddOrUpdateEntities(cntx, new SignalRHostStateSet(), new SignalRHostState[] { host }); host = x.ChangedEntities[0].UpdatedItem; } DateTime dt = DateTime.UtcNow.AddHours(-config.TimeWindowInHours); QueryExpresion qexpr = new QueryExpresion(); qexpr.OrderTks = new List <QToken>(new QToken[] { new QToken { TkName = "ID" }, new QToken { TkName = "desc" } }); qexpr.FilterTks = new List <QToken>(new QToken[] { new QToken { TkName = "ApplicationID == \"" + config.App.ID + "\" && ID > " + host.LastMsgId + " && TimeStamp > " + dt.Ticks } }); var msgs = msgsvc.QueryDatabaseLimited(cntx, new SignalRMessageSet(), qexpr, config.MaxBacklogMessages).ToArray(); if (msgs.Length > 0) { host.LastMsgId = msgs[0].ID; LastMessageId = (ulong)host.LastMsgId; IsLastMessageIdChanged = true; foreach (var e in from d in msgs orderby d.ID ascending select d) { OnReceived(0, (ulong)e.ID, ScaleoutMessage.FromBytes(e.MesssageData)); } } }
void FromBytesToBytesProducesCorrectValues() { var message = new Message("source", "key", "value"); var message2 = new Message("string", "more", "str"); var message3 = new Message("s", "l", "n"); var scaleoutMessage = new ScaleoutMessage(new List <Message>() { message, message2, message3 }); var bytes = scaleoutMessage.ToBytes(); var msg = ScaleoutMessage.FromBytes(bytes); Assert.True(scaleoutMessage.Messages.Count == 3); Assert.True(scaleoutMessage.Messages[0].Source == msg.Messages[0].Source, "Source is not the same"); Assert.True(scaleoutMessage.Messages[0].Key == msg.Messages[0].Key, "Key is not the same"); Assert.True(scaleoutMessage.Messages[0].GetString() == msg.Messages[0].GetString(), "Value is not the same"); }
protected override Task Send(int streamIndex, IList <Message> messages) { return(Task.Run(() => { var scaleoutMsg = new ScaleoutMessage(messages); var msg = new RmqMessage { StreamIndex = streamIndex, Id = 0, Body = scaleoutMsg.ToBytes() }; var body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(msg)); model.BasicPublish(this.configuration.ExchangeName, "", true, new BasicProperties(), body); })); }
public static ScaleoutMessage FromBrokeredMessage(BrokeredMessage brokeredMessage) { if (brokeredMessage == null) { throw new ArgumentNullException("brokeredMessage"); } var stream = brokeredMessage.GetBody <Stream>(); using (var ms = new MemoryStream()) { stream.CopyTo(ms); var message = ScaleoutMessage.FromBytes(ms.ToArray()); return(message); } }
private void OnMessage(int topicIndex, IEnumerable <BrokeredMessage> messages) { if (!messages.Any()) { // Force the topic to re-open if it was ever closed even if we didn't get any messages Open(topicIndex); } foreach (var message in messages) { using (message) { ScaleoutMessage scaleoutMessage = ServiceBusMessage.FromBrokeredMessage(message); OnReceived(topicIndex, (ulong)message.EnqueuedSequenceNumber, scaleoutMessage); } } }
public void MinMappingIdMovesWhenOverflow() { var store = new ScaleoutStore(5); int id = 0; for (int i = 0; i < store.FragmentSize + 1; i++) { for (int j = 0; j < store.FragmentCount; j++) { var message = new ScaleoutMessage(); store.Add(new ScaleoutMapping((ulong)id, message)); id++; } } Assert.Equal((ulong)store.FragmentSize - 1, store.MinMappingId); }
private void OnReceived_P(byte[] data) { BinaryFormatter ser = new BinaryFormatter(); Packet packet = null; using (MemoryStream ms = new MemoryStream()) { ms.Write(data, 0, data.Length); ms.Seek(0, SeekOrigin.Begin); packet = ser.Deserialize(ms) as Packet; } var message = ScaleoutMessage.FromBytes(packet.Data); var args = new OnReceivedArgs(); args.Id = packet.Id; args.Message = message; OnReceived(this, args); }
public static byte[] ToBytes(IList <Message> messages) { if (messages == null) { throw new ArgumentNullException("messages"); } using (var ms = new MemoryStream()) { var binaryWriter = new BinaryWriter(ms); var scaleoutMessage = new ScaleoutMessage(messages); var buffer = scaleoutMessage.ToBytes(); binaryWriter.Write(buffer.Length); binaryWriter.Write(buffer); return(ms.ToArray()); } }
private ScaleoutMessage GetJsonMessage(dynamic msg, out ulong msgId) { msgId = 0; if ((string)msg["status"] == "added") { DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(SignalRMessage)); byte[] bf = Encoding.UTF8.GetBytes((string)msg["data"]); MemoryStream strm = new MemoryStream(bf); strm.Position = 0; var e = ser.ReadObject(strm) as SignalRMessage; if (e.ApplicationID == config.App.ID) { msgId = (ulong)e.ID; return(ScaleoutMessage.FromBytes(e.MesssageData)); } else { return(null); } } return(null); }