Error while using ServiceBusProcessor - Azure.Messaging.ServiceBus SDK - azure

I am getting an exception after the StartProcessingAsync() method. The debug pointer goes to the "ProcessorErrorAsync" method. I followed similar steps provided in the link - https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/servicebus/Azure.Messaging.ServiceBus/samples/Sample04_Processor.md
Am I missing some steps here?
Exception Details: error.Exception.Message:
Method not found: 'System.Threading.Tasks.Task`1<System.Collections.Generic.IEnumerable`1<Microsoft.Azure.Amqp.AmqpMessage>> Microsoft.Azure.Amqp.ReceivingAmqpLink.ReceiveMessagesAsync(Int32, System.TimeSpan, System.TimeSpan, System.Threading.CancellationToken)'.
private void ListenerBind(string key, ServiceBusProcessorOptions onMessageOptions)
{
ServiceBusClient tempClient = this._cacheClient.Get(key);
ServiceBusProcessor tempProcessor = tempClient.CreateProcessor(this._topicName, this._subscriptionName, onMessageOptions);
try
{
//temp.OnMessageAsync(this.MessageProcessCallBackAsync, onMessageOptions);
tempProcessor.ProcessMessageAsync += MessageProcessCallBackAsync;
tempProcessor.ProcessErrorAsync += ProcessErrorAsync;
tempProcessor.StartProcessingAsync();
}
catch (InvalidOperationException ex)
{
this._logger.Log($"{ex.Message}", EventLevel.Informational);
}
catch (Exception ex)
{
this._logger.LogException(ex);
}
}
private Task ProcessErrorAsync(ProcessErrorEventArgs error)
{
Exception ex = new Exception(
$" , Action {error.ErrorSource}, " +
$" , Endpoint {error.FullyQualifiedNamespace}" +
$",EntityPath {error.EntityPath} "
, error.Exception);
this._logger.LogException(ex);
this._onErrorCallback(ex, string.Empty);
return Task.CompletedTask;
}

Related

Volley success and error code handle

I am basically new to volley but unlike apache http old libraries I used to do like this to handle response along with status code to show aler dialog regarding success and failed response:
#Override
protected String doInBackground(Void... params) {
String mre = null;
stringEntity=new StringEntity(jsonObject.toString());
httpPost.setEntity(stringEntity);
httpPost.setHeader("Content-type", "application/json");
httpResponse=httpClient.execute(httpPost);
int statusCode=httpResponse.getStatusLine().getStatusCode();
switch (statusCode){
case 200:
entity = httpResponse.getEntity();
System.out.println("Entity post is: "
+ EntityUtils.toString(entity));
mre = "200";
Log.d("SUCCESS","YES FINALLY");
Log.d("Ok",entity.toString());
break;
case 412:
mre = "412";
Log.d("412", "412 WE MEET AGAIN)");
break;
default:
mre="unknown";
Log.i("Unknown","Unknown Server Error");
}
} catch (IOException e) {
e.printStackTrace();
}
return mre;
}
#Override
protected void onPostExecute(String mre) {
super.onPostExecute(mre);
hideDialog();
if(mre.equalsIgnoreCase("200")){
//HANDLE HERE
}
else if(mre.equalsIgnoreCase("412")){
//HANDLE HERE
}
else
if(mre.equalsIgnoreCase("unknown")){
//HANDLE HERE
}
But in volley I am confused, I need to handle every status code received from server so that I can show user a message.(SUCCESS/FAILED )
A bit help would deeply appreciated

C++/CLI code doesn't enter .then part of the create_task function

This is the code that I have:
void MainPage::OnNavigatedTo(NavigationEventArgs^ e)
{
XTRACE(L"=========================================will start onNavigated ");
auto mediaCapture = ref new Windows::Media::Capture::MediaCapture();
m_mediaCaptureMgr = mediaCapture;
IAsyncAction ^asyncAction = m_mediaCaptureMgr->InitializeAsync();
try
{
create_task(asyncAction).then([this](task<void> initTask)
{
XTRACE(L"=========================================will start onNavigated 2");
try
{
initTask.get();
auto mediaCapture = m_mediaCaptureMgr.Get();
if (mediaCapture->MediaCaptureSettings->VideoDeviceId != nullptr && mediaCapture->MediaCaptureSettings->AudioDeviceId != nullptr)
{
String ^fileName;
fileName = VIDEO_FILE_NAME;
XTRACE(L"=================================Device initialized successful\n");
create_task(KnownFolders::VideosLibrary->CreateFileAsync(fileName, Windows::Storage::CreationCollisionOption::GenerateUniqueName))
.then([this](task<StorageFile^> fileTask)
{
XTRACE(L"=================================Create record file successful\n");
m_recordStorageFile = fileTask.get();
MediaEncodingProfile^ recordProfile = nullptr;
recordProfile = MediaEncodingProfile::CreateMp4(Windows::Media::MediaProperties::VideoEncodingQuality::Auto);
stream = ref new InMemoryRandomAccessStream();
return m_mediaCaptureMgr->StartRecordToStreamAsync(recordProfile, stream);
}).then([this](task<void> recordTask)
{
try
{
recordTask.get();
XTRACE(L"=================================Start Record successful\n");
}
catch (Exception ^e)
{
XTRACE(L"======ERRROR is : %d", e);
}
});
}
else
{
XTRACE(L"=================================No VideoDevice/AudioDevice Found\n");
}
XTRACE(L"=================================WILL EXIT \n");
}
catch (Exception ^ e)
{
XTRACE(L"============================================ERROR IS: %d\n", e);
}
}
);
}
catch (Exception ^ e)
{
XTRACE(L"============================================before create task ERROR IS: %d\n", e);
}
XTRACE(L"=================================SLEEP 20000====================================\n");
std::chrono::milliseconds dura(20000);
std::this_thread::sleep_for(dura);
XTRACE(L"=================================TIME ENDED====================================\n");
// stop device detection
try
{
XTRACE(L"=================================Stopping Record\n");
create_task(m_mediaCaptureMgr->StopRecordAsync())
.then([this](task<void> recordTask)
{
try
{
recordTask.get();
XTRACE(L"=================================Stop record successful: %d\n", stream->Size);
}
catch (Exception ^e)
{
XTRACE(L"=================================ERROR while stoping 2: %d\n", e);
}
});
}
catch (Exception ^e)
{
XTRACE(L"=================================ERROR try catch 3 stoping: %d\n", e);
}
CloseHandle(ghEvent);
// destruct the device manager
XTRACE(L"=====================================================================END\n");
}
In the log I see:
=========================================will start onNavigated
And then directly:
=====================================================================
=================================SLEEP 20000====================================
What is strange is that I had this code in a unittest and it worked, I created a new windows phone project with a UI and it doesn't work
Apparently it was because of the ThreadSleep:
std::chrono::milliseconds dura(20000);
std::this_thread::sleep_for(dura);
In the library project where I was working I was using a different sleep, provided by the library, and that would work. So this was the line that would cause the application to block itself.
I worked my way around this by including 2 buttons in the app, for the start and stop recording.

how to check if device is registered for windows phone push notification

I am using notification hub to register my windows phone device for push notification service.Once if I register my device and again if I register my device for push notification I am getting two notifications means a single device is registering for two time.Can anyone please tell me how to prevent a user to register for more than once.
My code is as:
public static async Task SetupPushNotifications()
{
await RegisterWithNotificationHub();
}
private static HttpNotificationChannel CreateHttpNotificationChannel(string channelName)
{
var httpChannel = HttpNotificationChannel.Find(channelName);
#endregion
return httpChannel;
}
private static async Task RegisterWithNotificationHub()
{
try
{
// requesting a channel from MPNS
App.NotificationChannel = CreateHttpNotificationChannel("");
App.ClientHub = new NotificationHub(
"",""
);
var storedTagsForUser = await GetRegistrationsTagsFromBackEnd();
await RegisterTemplateNotificationWithNotificationHub(storedTagsForUser);
}
catch (Exception exc)
{
Debug.WriteLine(exc);
}
}
private static async Task RegisterTemplateNotificationWithNotificationHub(IEnumerable<string> tags)
{
var toastMessageTemplate =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<wp:Notification xmlns:wp=\"WPNotification\">" +
"<wp:Toast>" +
"<wp:Text1>$(oppTitleValue)</wp:Text1>" +
"<wp:Text2>$(myToastMessage)</wp:Text2>" +
"<wp:Param>$(pageToOpen)</wp:Param>" +
"</wp:Toast>" +
"</wp:Notification>";
try
{
await App.ClientHub.RegisterTemplateAsync(
App.NotificationChannel.ChannelUri.AbsoluteUri,
xmlTemplate: toastMessageTemplate,
templateName: TemplateRegistrationName,
tags: tags);
}
catch (Exception exc)
{
Debug.WriteLine("Error registering template notification with notification hubs: " + exc);
}
}
You can check if the channel already exists by calling HttpNotificationChannel.Find(channelName). It will return null if it doesn't.
So you would only want to create a channel if it doesnt't already exist. For example
private void RegisterPushChannel()
{
HttpNotificationChannel currentChannel = HttpNotificationChannel.Find("MyPushChannel");
if (currentChannel == null)
{
currentChannel = new HttpNotificationChannel("MyPushChannel");
currentChannel.Open();
currentChannel.BindToShellTile();
currentChannel.BindToShellToast();
}
}

platformRequest not working in J2ME

I'm triyng to play .mp3 file using platformRequest(). I verified the file path and it is correct. And I'm using Nokia 210 for testing. Please help me to fix this issue.
try {
platformRequest("file:///C:/song.mp3");
} catch (ConnectionNotFoundException ex) {
ex.printStackTrace();
}
I know you have already verified whether there is file or not. though check my below code once and post comment with results.
Added -
public boolean isFileExisted(String path) {
boolean isExisted = false;
FileConnection filecon = null;
try {
filecon = (FileConnection) Connector.open(path, Connector.READ);
isExisted = filecon.exists();
} catch (java.lang.SecurityException e) {
} catch (Exception e) {
} finally {
try {
if (filecon != null) {
filecon.close();
}
catch (Exception e) {
}
}
return isExisted;
}
}
public void playFileFromSDCard() {
String path1 = "file:///C:/song.mp3";
String path2 = "file:///E:/song.mp3";
if (isFileExisted(path1)) {
try {
System.out.println("path1 exist -> calling platform request " + path1);
platformRequest(path1);
} catch (ConnectionNotFoundException ex) {
ex.printStackTrace();
}
}
else if (isFileExisted(path2)) {
try {
System.out.println("path2 exist -> calling platform request " + path2);
platformRequest(path2);
} catch (ConnectionNotFoundException ex) {
ex.printStackTrace();
}
}
else {
System.out.println("both path doesnt exists");
}
}
After so many searches i found some reasons for the issue. This may help for people in future who is having the same problem. refer the following links.
Open file with MIDlet.platformRequest() ,
How to play media file in System media player in j2me????

PushSharp for APNS works on local server but not on azure

I am using push sharp in a ASP.NET web api server. on my local computer everything works like a charm for GCM and APNS but once uploaded to azure only the GCM messages work. the APNS is not working, not throwing exceptions nothing. I have traces in every event the push broker throws but no trace message is called. not even the message queued...
Here is my initialization code:
public PushNotificationManager()
{
_pushService = new PushBroker();
_pushService.OnChannelCreated += OnChannelCreated;
_pushService.OnChannelDestroyed += OnChannelDestroyed;
_pushService.OnChannelException += OnChannelException;
_pushService.OnDeviceSubscriptionChanged += OnDeciveSubscriptionChanged;
_pushService.OnDeviceSubscriptionExpired += OnDeviceSubscriptionExpired;
_pushService.OnNotificationFailed += OnNorificationFailed;
_pushService.OnNotificationRequeue += OnNotificationQueued;
_pushService.OnNotificationSent += OnNOtificationSend;
_pushService.OnServiceException += OnServiceException;
InitAndroidPushService();
InitApplePushService();
}
private void InitApplePushService()
{
try
{
string appDataPath = HttpContext.Current.Server.MapPath("~/app_data");
//***** Development Server *****//
//string file = Path.Combine(appDataPath, "PushSharp.PushCert.Development.p12");
//var appleCert = File.ReadAllBytes(file);
// _applePushService = new ApplePushService(new ApplePushChannelSettings(false, appleCert, "XXXXXXX"));
//***** Production Server *****//
string file = Path.Combine(appDataPath, "PushSharp.PushCert.Production.p12");
var appleCert = File.ReadAllBytes(file);
_pushService.RegisterAppleService(new ApplePushChannelSettings(true, appleCert, "XXXXXX"));
Trace.TraceInformation("ApplePushService initialized succesfully");
}
catch (Exception e)
{
Trace.TraceError("Error initializing ApplePushService : " + e);
throw;
}
}
private void InitAndroidPushService()
{
try
{
_pushService.RegisterGcmService(new GcmPushChannelSettings("XXXXXX", "XXXXXX",
"XXXXX"));
Trace.TraceInformation("GooglePushService initialized succesfully");
}
catch (Exception e)
{
Trace.TraceError("Error initializing AndroidPushService : " + e);
}
}
Has anyone enountered such a thing?

Resources