Search in sources :

Example 1 with EventNotificationConfig

use of com.google.api.services.cloudiot.v1.model.EventNotificationConfig in project java-docs-samples by GoogleCloudPlatform.

the class DeviceRegistryExample method createRegistry.

// [START iot_create_registry]
/**
 * Create a registry for Cloud IoT.
 */
public static void createRegistry(String cloudRegion, String projectId, String registryName, String pubsubTopicPath) throws GeneralSecurityException, IOException {
    GoogleCredential credential = GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
    JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
    HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
    final CloudIot service = new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init).setApplicationName(APP_NAME).build();
    final String projectPath = "projects/" + projectId + "/locations/" + cloudRegion;
    final String fullPubsubPath = "projects/" + projectId + "/topics/" + pubsubTopicPath;
    DeviceRegistry registry = new DeviceRegistry();
    EventNotificationConfig notificationConfig = new EventNotificationConfig();
    notificationConfig.setPubsubTopicName(fullPubsubPath);
    List<EventNotificationConfig> notificationConfigs = new ArrayList<EventNotificationConfig>();
    notificationConfigs.add(notificationConfig);
    registry.setEventNotificationConfigs(notificationConfigs);
    registry.setId(registryName);
    DeviceRegistry reg = service.projects().locations().registries().create(projectPath, registry).execute();
    System.out.println("Created registry: " + reg.getName());
}
Also used : CloudIot(com.google.api.services.cloudiot.v1.CloudIot) DeviceRegistry(com.google.api.services.cloudiot.v1.model.DeviceRegistry) JsonFactory(com.google.api.client.json.JsonFactory) ArrayList(java.util.ArrayList) EventNotificationConfig(com.google.api.services.cloudiot.v1.model.EventNotificationConfig) GoogleCredential(com.google.api.client.googleapis.auth.oauth2.GoogleCredential) HttpRequestInitializer(com.google.api.client.http.HttpRequestInitializer)

Aggregations

GoogleCredential (com.google.api.client.googleapis.auth.oauth2.GoogleCredential)1 HttpRequestInitializer (com.google.api.client.http.HttpRequestInitializer)1 JsonFactory (com.google.api.client.json.JsonFactory)1 CloudIot (com.google.api.services.cloudiot.v1.CloudIot)1 DeviceRegistry (com.google.api.services.cloudiot.v1.model.DeviceRegistry)1 EventNotificationConfig (com.google.api.services.cloudiot.v1.model.EventNotificationConfig)1 ArrayList (java.util.ArrayList)1