public void TestBasicMessageSubscriptionWithSubtopic() { SetLatch(); SetMessage(); string subtopic = "sub" + Random.Next(); SubscriptionOptions subscriptionOptions = new SubscriptionOptions(); subscriptionOptions.Subtopic = subtopic; subscription = Backendless.Messaging.Subscribe( TEST_CHANNEL, new ResponseCallback<List<Message>>( this ) { ResponseHandler = messages => { try { Assert.IsNotNull( messages, "Server returned a null object instead of messages list" ); Assert.IsFalse( messages.Count == 0, "Server returned an empty messages list" ); foreach( Message resultMessage in messages ) { if( resultMessage.MessageId.Equals( messageStatus.MessageId ) ) { Assert.AreEqual( message, resultMessage.Data, "Server returned a message with a wrong message data" ); Assert.AreEqual( messageStatus.MessageId, resultMessage.MessageId, "Server returned a message with a wrong messageId" ); latch.Signal(); } } } catch( System.Exception t ) { FailCountDownWith( t ); } } }, subscriptionOptions ); var publishOptions = new PublishOptions(); publishOptions.Subtopic = subtopic; messageStatus = Backendless.Messaging.Publish( message, TEST_CHANNEL, publishOptions ); Assert.IsNotNull( messageStatus.MessageId, "Server didn't set a messageId for the message" ); Assert.IsTrue( messageStatus.Status.Equals( PublishStatusEnum.PUBLISHED ), "Message status was not set as published" ); Await(); CheckResult(); }
public void TestBasicMessageSubscriptionWithSelector() { SetLatch(); SetMessage(); string headerKey = "header_" + Random.Next(); string headerValue = "someValue"; headers = new Dictionary<string, string>(); headers.Add( headerKey, headerValue ); var subscriptionOptions = new SubscriptionOptions(); subscriptionOptions.Selector = headerKey + "='" + headerValue + "'"; subscription = Backendless.Messaging.Subscribe( TEST_CHANNEL, new ResponseCallback<List<Message>>( this ) { ResponseHandler = messages => { try { Assert.IsNotNull( messages, "Server returned a null object instead of messages list" ); Assert.IsFalse( messages.Count == 0, "Server returned an empty messages list" ); foreach( Message resultMessage in messages ) { if( resultMessage.MessageId.Equals( messageStatus.MessageId ) ) { Assert.AreEqual( message, resultMessage.Data, "Server returned a message with a wrong message data" ); Assert.IsTrue( resultMessage.Headers.ContainsKey( headerKey ), "Server returned a message with wrong headers" ); Assert.AreEqual( headerValue, resultMessage.Headers[headerKey], "Server returned a message with wrong headers" ); Assert.AreEqual( messageStatus.MessageId, resultMessage.MessageId, "Server returned a message with a wrong messageId" ); latch.Signal(); } } } catch( System.Exception t ) { FailCountDownWith( t ); } } }, subscriptionOptions ); var publishOptions = new PublishOptions {Headers = headers}; messageStatus = Backendless.Messaging.Publish( message, TEST_CHANNEL, publishOptions ); Assert.IsNotNull( messageStatus.MessageId, "Server didn't set a messageId for the message" ); Assert.IsTrue( messageStatus.Status.Equals( PublishStatusEnum.PUBLISHED ), "Message status was not set as published" ); Await(); CheckResult(); }
void Publish() { mWaiting.SetActive(true); PublishOptions publishOptions = new PublishOptions(mName); AsyncCallback<MessageStatus> callback = new AsyncCallback<MessageStatus>( status => { mIsPublishFinish = true; mIsPublishSuccess = true; }, fault => { mResultMessage = "Error\n\nCode = " + fault.FaultCode + "\nMessage = " + fault.Message; mIsPublishFinish = true; mIsPublishSuccess = false; }); Backendless.Messaging.Publish(mPublishMessage, mChannel, publishOptions, callback); }
void SendMessage() { mWaiting.SetActive(true); PublishOptions publishOptions = new PublishOptions(); if (mForceNotify == true) { publishOptions.AddHeader(PublishOptions.ANDROID_TICKER_TEXT_TAG, mSendMessage); publishOptions.AddHeader(PublishOptions.ANDROID_CONTENT_TITLE_TAG, "Backendless example"); publishOptions.AddHeader(PublishOptions.ANDROID_CONTENT_TEXT_TAG, mSendMessage); } DeliveryOptions deliveryOptions = new DeliveryOptions(); deliveryOptions.PushBroadcast = DeliveryOptions.ALL; AsyncCallback<MessageStatus> callback = new AsyncCallback<MessageStatus>( status => { mIsSendMessageFinish = true; mIsSendMessageSuccess = true; }, fault => { mResultMessage = "Error\n\nCode = " + fault.FaultCode + "\nMessage = " + fault.Message; mIsSendMessageFinish = true; mIsSendMessageSuccess = false; }); Backendless.Messaging.Publish(mSendMessage, publishOptions, deliveryOptions, callback); }
public void publishMessageWithHeadersNoSubtopicTest() { try { string channel = "testChannel"; object message = "Test message! Hello Word!!!"; Dictionary<string, string> dict = new Dictionary<string, string>(); dict.Add("City", "Kiev"); dict.Add("Temp", "22"); PublishOptions option = new PublishOptions { PublisherId = "testPablisher", Headers = dict }; var m = messagingService.Publish(message, channel, option); Assert.IsNotNull(m.MessageId); } catch (BackendlessException ex) { Assert.Fail(ex.Message); } }
public void cancelScheduleMessageWithWasPublishedTest() { try { string channel = "testChannel"; object message = "Test message! Hello Word!!!"; Dictionary<string, string> dict = new Dictionary<string, string>(); dict.Add("City", "Kiev"); dict.Add("Temp", "22"); PublishOptions option = new PublishOptions { PublisherId = "testPublisher", Headers = dict }; DeliveryOptions delivery = new DeliveryOptions { }; var m = messagingService.Publish(message, channel, option); var cancel = messagingService.Cancel(m.MessageId); Assert.IsNotNull(cancel); } catch (BackendlessException ex) { Assert.AreEqual("5040", ex.Code); } }
public void publishMessageArrayValueTest() { try { string channel = "testChannel"; object message = new List<Person> { new Person { Name = "Vasya", Age = 22 } }; Dictionary<string, string> dict = new Dictionary<string, string>(); dict.Add("City", "Kiev"); dict.Add("Temp", "22"); PublishOptions option = new PublishOptions { PublisherId = "testPablisher", Headers = dict, Subtopic = "testSubtopic" }; var m = messagingService.Publish(message, channel, option); Assert.IsNotNull(m.MessageId); } catch (BackendlessException ex) { Assert.Fail(ex.Message); } }