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());
}
Aggregations