2017-09-28 1 views
0

알림 허브가 있는데 허브 허브가 있고 거의 가득 찼습니다. 다른 허브를 만들 겠지만 프로그래밍 방식으로 (안드로이드)를 어떻게 알 수 있습니까? 어느 쪽을 입력해야합니까? 안드로이드 소스 코드 :가득 차 있지 않은 허브 알림을받는 방법은 무엇입니까?

public class NotificationSettings { 

    public static String SenderId = "MyFirebaseSenderId"; 
    public static String HubName = "myhub-hub"; 
    public static String HubListenConnectionString = "Endpoint=sb://myapp.serv.../;SharedAccessKeyName=D..ure;SharedAccessKey=K..t/n8I/X..="; 
} 

RegistrationIntent : 이제

public class RegistrationIntentService extends IntentService { 

    private static final String TAG = "RegIntentService"; 

    private NotificationHub hub; 

    public RegistrationIntentService() { 
     super(TAG); 
    } 

    public ApplicationUtils getApplicationUtils() { 
     return (ApplicationUtils) getApplication(); 
    } 

    @Override 
    protected void onHandleIntent(Intent intent) { 

     SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); 
     String resultString = null; 
     String regID = null; 
     String storedToken = null; 
     String tag = null; 
     try { 
      tag ="_UserId:" + getApplicationUtils().getUsuario().Id; 

     } catch (Exception e){ 
      return; 
     } 

     try { 
      if(FirebaseInstanceId.getInstance() == null){ 
      FirebaseApp.initializeApp(this); 
      } 

      String FCM_token = FirebaseInstanceId.getInstance().getToken(); 
      SaveSharedPreferences.setFCM(getApplicationContext(),FCM_token); 
      Log.d(TAG, "FCM Registration Token: " + FCM_token); 

      // Storing the registration id that indicates whether the generated token has been 
      // sent to your server. If it is not stored, send the token to your server, 
      // otherwise your server should have already received the token. 
      if (((regID=sharedPreferences.getString("registrationID", null)) == null)){ 

       NotificationHub hub = new NotificationHub(NotificationSettings.HubName, 
         NotificationSettings.HubListenConnectionString, this); 
       Log.d(TAG, "Attempting a new registration with NH using FCM token : " + FCM_token); 
       regID = hub.register(FCM_token, tag).getRegistrationId(); 

       // If you want to use tags... 
       // Refer to : https://azure.microsoft.com/en-us/documentation/articles/notification-hubs-routing-tag-expressions/ 
       // regID = hub.register(token, "tag1,tag2").getRegistrationId(); 

       resultString = "New NH Registration Successfully - RegId : " + regID; 
       Log.d(TAG, resultString); 

       sharedPreferences.edit().putString("registrationID", regID).apply(); 
       sharedPreferences.edit().putString("FCMtoken", FCM_token).apply(); 
      } 

      // Check if the token may have been compromised and needs refreshing. 
      else if (!((storedToken=sharedPreferences.getString("FCMtoken", "")).equals(FCM_token))) { 

       NotificationHub hub = new NotificationHub(NotificationSettings.HubName, 
         NotificationSettings.HubListenConnectionString, this); 
       Log.d(TAG, "NH Registration refreshing with token : " + FCM_token); 
       regID = hub.register(FCM_token, tag).getRegistrationId(); 

       // If you want to use tags... 
       // Refer to : https://azure.microsoft.com/en-us/documentation/articles/notification-hubs-routing-tag-expressions/ 
       // regID = hub.register(token, "tag1,tag2").getRegistrationId(); 

       resultString = "New NH Registration Successfully - RegId : " + regID; 
       Log.d(TAG, resultString); 

       sharedPreferences.edit().putString("registrationID", regID).apply(); 
       sharedPreferences.edit().putString("FCMtoken", FCM_token).apply(); 
      } 

      else { 
       resultString = "Previously Registered Successfully - RegId : " + regID; 
      } 
     } ............................................. 

는,이 경우에 중요 할 것인지 모르겠어요, 아래에있는 내 downend 코드를 다음과 같습니다. 하지만 C#으로 개발되었습니다. 닷넷 :

public static async void sendPushNotification(ApiController controller, DataObjects.Notification notification) 
     { 
      // Get the settings for the server project. 
      HttpConfiguration config = controller.Configuration; 

      MobileAppSettingsDictionary settings = 
       controller.Configuration.GetMobileAppSettingsProvider().GetMobileAppSettings(); 

      // Get the Notification Hubs credentials for the Mobile App. 
      string notificationHubName = settings.NotificationHubName; 
      string notificationHubConnection = settings 
       .Connections[MobileAppSettingsKeys.NotificationHubConnectionString].ConnectionString; 

      // Create a new Notification Hub client. 
      NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString(notificationHubConnection, notificationHubName); 

      // Android payload 
      JObject data = new JObject(); 

      data.Add("Id", notification.Id); 
      data.Add("Descricao", notification.Descricao); 
     ... 
      //alteração com a colocação da tag priority em caso de erro teste sem 
      var androidNotificationPayload = "{ \"data\" : {\"message\":" + JsonConvert.SerializeObject(data) + "}}"; 

      try 
      { 
       // Send the push notification and log the results. 
       String tag = "_UserId:"+notification.Id_usuario; 
       //var result = await hub.SendGcmNativeNotificationAsync(androidNotificationPayload); 
       var result = await hub.SendGcmNativeNotificationAsync(androidNotificationPayload, tag); 

       // Write the success result to the logs. 
       config.Services.GetTraceWriter().Info(result.State.ToString()); 
      } 
      catch (System.Exception ex) 
      { 
       // Write the failure result to the logs. 
       config.Services.GetTraceWriter().Error(ex.Message, null, "Push.SendAsync Error"); 
      } 
     } 

이 문제에 대한 많은 도움이 필요합니다. 고맙습니다.

답변

1

귀하의 설명에 따르면, 귀하는 등록이 가득 차 있는지 여부를 확인한 후 (클라이언트 측이 아닌) 통지 허브에 새로운 사용자를 삽입하는 API 방법을 작성할 것을 제안합니다.

사용할 수 있습니다. NotificationHubClient.GetAllRegistrationsAsync 로컬로 모든 AllRegistrations을 가져 오는 방법. 그 숫자를 세어 보았습니다.

성공적으로 확인한 후 사용자 입력을 확인합니다.

워크 플로는 다음과 같습니다

새로운 등록 된 사용자 :

클라이언트 : 서버 웹 API 메서드에 사용자 정보를 전송

서버 : 알림 허브가 가득 확인 (전화 NotificationHubClient.GetAllRegistrationsAsync 또는 직접 등록한 사용자가 실패한 경우 새 허브에 등록)

알림 허브는 다른 가격 책정 등급을 제공합니다.

여러 활성 장치를 지원하기 위해 가격 책정 단계를 확장하는 것이 좋습니다.

enter image description here

+0

Tks! 나는이 방법을 연구하고 발견했다. 나는 200k 명의 사용자를 사용한다. 다음은 그 위에 있습니다. –

관련 문제