static void Main(string[] args) { var configCheck = new ConfigurationWrapper(); string yourProjectId = ""; // enter your projectid here or use app.config string yourtoken = ""; // enter your token or use app.config if (String.IsNullOrEmpty(yourProjectId)) { yourProjectId = configCheck.BlacksmithProjectId; } if (String.IsNullOrEmpty(yourtoken)) { yourtoken = configCheck.BlacksmithToken; } var client = new Client(yourProjectId, yourtoken); var pusher = new Timer { AutoReset = true, Interval = 1000, Enabled = true }; var one = new Timer { AutoReset = true, Interval = 2500, Enabled = true }; var bunch = new Timer { AutoReset = true, Interval = 5000, Enabled = true }; // let's start pushing messages into the queue // the queue name is based on the class name pusher.Elapsed += (sender, eventArgs) => client .Queue<MyMessage>() .Push(new MyMessage { Text = string.Format("Hello, World from {0}!", ++_count) }); // I will handle try catches for you for // when it comes to deserializing and executing your processing code // also, I will delete the message from the queue on success! one.Elapsed += (sender, eventArgs) => client.Queue<MyMessage>() .Next() .OnError(Console.WriteLine) .Consume((m, ctx) => { Console.WriteLine("consuming one: {0}", m.Target.Text); }); // Can't wait, get a bunch of messages back and consume each one bunch.Elapsed += (sender, eventArgs) => client.Queue<MyMessage>() .Get(5) .ForEach(r => r.Consume((m, ctx) => { Console.WriteLine("{0} : {1}", m.Id, m.Target.Text); })); Console.ReadLine(); // clear the queue pusher.Stop(); bunch.Stop(); client.Queue<MyMessage>().Clear(); }
/// <summary> /// Can tell you what the preferred queue name is for a particular type. Helpful for debugging queue issues. /// </summary> /// <param name="type"></param> /// <returns></returns> public static string GetQueueName(this Type type) { var config = new ConfigurationWrapper(); if (string.IsNullOrEmpty(config.OptionalFixedQueueName)) { var attributes = type.GetCustomAttributes(typeof(QueueNameAttribute), false); if (!attributes.Any()) { return(FindQueueNameMappingOrUseFullName(type)); } var attribute = attributes.Cast <QueueNameAttribute>().First(); return(attribute.Name); } return(config.OptionalFixedQueueName); }
public void Token_Always_Returns_A_Non_Null() { var config = new ConfigurationWrapper(); config.BlacksmithToken.Should().NotBe(null); }
public void ProjectID_Always_Returns_A_Non_Null() { var config = new ConfigurationWrapper(); config.BlacksmithProjectId.Should().NotBe(null); }
public void Optional_fixed_qeuename_should_not_return_null() { var config = new ConfigurationWrapper(); config.OptionalFixedQueueName.Should().NotBe(null); }