Whatever message this page gives is out now! Go check it out!
add cloudconfiguration alias=pubsubdemo servicename=pubsubset cloudconfiguration pubsubdemo elementCountThreshold=102 requestByteThreshold=2048 delayThreshold=10mset cloudconfiguration pubsubdemo publisher.endpoint=pubsub.googleapis.com subscriber.endpoint=us-east1-pubsub.googleapis.com:443 enableMessageOrdering=false enableCompression=False compressionBytesThreshold=1 delayThreshold='2m'{
"data": string/struct/CFC/query/array/binary data
"attributes": {
string: string,
...
},
"messageId": string,
"publishTime": string,
"orderingKey": string
}Message = {
MessageID: "",
Data: “Hello World!”,
Attributes: {
year: “2020”,
author: “Martin Kleppman”
}, // Attribute’s key-value pairs must be only strings. Other data types are not supported.
OrderingKey: "",
PublishTime: "",
AttributesCount: 2,
AckId: "",
DeliveryAttempts: 1
}Message = {
MessageID: "",
Data: “Hello World!”,
Attributes: {
year: “2020”,
author: “Martin Kleppmann”
}, // Attribute’s key-value pairs must be only strings. Other data types are not supported.
OrderingKey: "",
PublishTime: "",
AttributesCount: 2
}createTopic(topicName [, structAttributes])| Parameter | Description | Required |
| topicName | Name of the topic to be created. | Yes |
messageRetentionDuration | Specifies how long the Pub/Sub topic retains messages after publication. After the message retention duration is over, Pub/Sub might discard the message regardless of its acknowledgment state. The acceptable range of values of a duration of a message in a topic is 10 minutes to 31 days. The duration parameters accepted are:
| Yes |
schemaSettings | Struct of the following:
| Yes |
labels | Topic label as key-value pairs. | Yes |
messageStoragePolicy | Specifies which regions your messages are stored in, you can configure a message storage policy on your topic. | Yes |
kmsKeyName | Specifies if the topic is encrypted with a CMEK(customer-managed encryption key). Pub/Sub encrypts messages with Google-managed keys by default. For more information, see this doc. | Yes |
<cfscript>
cred = {
projectId : "<your project id>",
credentialJsonFilePath : "<path to your credentials json file>"
}
conf = {
serviceName : "pubsub"
}
pubsubclient=getCloudService(cred, conf)
topicName = "mytopic"
topicAttributes = {
messageRetentionDuration : "600s",
schemaSettings : {
schemaName : "my-schema",
schemaEncoding : "JSON" // or "BINARY"
},
labels : {
"shape" : "circle",
"color" : "green"
},
messageStoragePolicy: ["asia-northeast1"],
kmsKeyName = "projects/my-gcp-project/locations/asia-northeast1/keyRings/customKMSKey/cryptoKeys/customManagedKey"
}
Topic = pubsubClient.createTopic(topicName, topicAttributes)
</cfscript>pubSubClient.listTopics(listAttributesStruct)| Parameter | Description | Required |
| pageSize | The maximum number of subscriptions to return. | No |
| nextPageToken | The value to return the next page of subsciptions. | No |
<cfscript>
cred = {
projectId : "<your project id>",
credentialJsonFilePath : "<path to your credentials json file>"
}
conf = {
serviceName : "pubsub"
}
Pubsubclient = getCloudService(cred, conf)
topics = pubsubclient.listTopics({pageSize: 100})
Writedump(topics)
</cfscript>deleteTopic(topicName)Parameter | Description |
topicName | Name of the topic to be deleted. |
<cfscript>
cred = {
projectId : "<your project id>",
credentialJsonFilePath : "<path to your credentials json file>"
}
conf = {
serviceName : "pubsub"
}
pubsubclient=getCloudService(cred, conf)
topicName="mytopic"
pubsubclient.createTopic(topicName)
pubsubclient.deleteTopic(topicName)
</cfscript>listTopicSubscriptions(topicName)Parameter | Description |
topicName | Name of the topic that has subscriptions. |
<cfscript>
cred = {
projectId : "<your project id>",
credentialJsonFilePath : "<path to your credentials json file>"
}
conf = {
serviceName : "pubsub"
}
pubsubclient=getCloudService(cred, conf)
topicName="mytopic"
subName1="subscription_01"
subName2="subscription_02"
subscriptionMetadata1 = {
"subscriptionName" : subName1
}
subscriptionMetadata2 = {
"subscriptionName" : subName2
}
topic=pubsubclient.createTopic(topicName)
// add a subscription
subscription1=topic.subscribe(subscriptionMetadata1)
subscription2=topic.subscribe(subscriptionMetadata2)
subscriptions = topic.listSubscriptions()
writeDump(subscriptions)
</cfscript>updateTopic(topicName, topicAttributes)<cfscript>
cred = {
projectId : "<your project id>",
credentialJsonFilePath : "<path to your credentials json file>"
}
conf = {
serviceName : "pubsub"
}
pubsubclient=getCloudService(cred, conf)
topicName = "mytopic"
topicAttributes= {
labels : {
shape : "square",
color : "blue"
},
messageStoragePolicy: ["asia-east1-a", "europe-west1-c"],
messageRetentionDuration: "600s",
schemaSettings : {
schemaName : "testSchema",
schemaEncoding : "Binary"
}
}
topic = pubsubclient.createTopic(topicName, topicAttributes)
updatedTopicAttributes = {
labels : {
size : "10cm",
},
messageRetentionDuration: "300s"
}
pubsubclient.updateTopic(topicName, updatedTopicAttributes)
</cfscript>detachSubscription(subscriptionName)Parameter | Description | Required |
subscriptionName | Name of the subscription to be detached from a topic. The subscription does not get deleted. It can be attached to another topic or re-attached to the original topic. | Yes |
<cfscript>
cred = {
projectId : "<your project id>",
credentialJsonFilePath : "<path to your credentials json file>"
}
conf = {
serviceName : "pubsub"
}
pubsubclient=getCloudService(cred, conf)
topicName = "myTopic"
subName="mySubscription"
subscriptionAttributes= {
"subscriptionName" : subName
}
topic = pubsubclient.createTopic(topicName)
subscription=topic.subscribe(subscriptionMetadata)
topic.detachSubscription(subName)
</cfscript>Parameter | Description | Required |
| topicName | The name of the topic. | Yes |
SubscriptionName | Subscription ID | Yes |
deliveryConfig | Struct of the following:
| Yes |
retryPolicy | Struct of the following:
| Yes |
deadLetterPolicy | Struct of the following:
| Yes |
labels | Struct containing- author, year, env. | Yes |
filter | Filter attributes of the topic. | Yes |
<cfscript>
cred = {
projectId : "<your project id>",
credentialJsonFilePath : "<path to your credentials json file>"
}
conf = {
serviceName : "pubsub"
}
pubsubclient=getCloudService(cred, conf)
topicName = "myTopic"
subName= "mySubscription"
subscriptionDetails = {
subscriptionName : subName,
topicName : topicName,
AckDeadlineSeconds : "600s",
enableExactlyOnceDelivery : false,
enableMessageOrdering : false,
retainAckedMessages : false,
MessageRetentionDuration = "700s"
filter = "attributes.color='green"
}
subscription= pubsubclient.subscribe(subscriptionDetails)
label="listProjectSubscriptions")
newAttributes = {
subscriptionName : subName,
enableExactlyOnceDelivery : true,
AckDeadlineSeconds : "400s",
enableMessageOrdering : true,
retainAckedMessages : true,
MessageRetentionDuration : "120s"
filter = "attributes.color='red"
}
pubsubClient.updateSubscription(newAttributes)
</cfscript>deleteSubscription(subscriptionName)Parameter | Description | Required |
subscriptionName | Name of the subscription to be deleted from a topic. | Yes |
<cfscript>
cred = {
projectId : "<your project id>",
credentialJsonFilePath : "<path to your credentials json file>"
}
conf = {
serviceName : "pubsub"
}
pubsubclient=getCloudService(cred, conf)
topicName = "myTopic"
subName="mySubscription"
subscriptionAttributes = {
"subscriptionName" : subName
}
topic = pubsubclient.createTopic(topicName)
topic.subscribe(subscriptionAttributes)
topic.deleteSubscription(subName)
</cfscript>publish(messageAttributes)| Parameter | Description | Required |
| data | The data to publish in the topic. | Yes |
| attributes | Struct of:
| Yes |
| orderingKey | The filter to apply to the topic. | Yes |
<cfscript>
cred = {
projectId : "<your project id>",
credentialJsonFilePath : "<path to your credentials json file>"
}
conf = {
serviceName : "pubsub"
}
pubsubclient=getCloudService(cred, conf)
topicName="myTopic"
topic= pubsubClient.createTopic(topicName)
message = {
data: "hello world!"
}
subName = "mysubscription"
subscriptionAttributes= {
"subscriptionName" : subName,
"topicName" : topicName
}
topic.subscribe(subscriptionAttributes)
cffuture=topicObj.publish(message)
MessageID = Cffuture.get()
writeOutput("Message with ID #MessageID# published")
</cfscript>messageMetadata = {
data: "Hello World 12345!",
attributes: {
author: "Martin Kleppmann",
age: 33,
}
}
publishedFuture = topic.publish(messageMetadata)
WriteDump(publishedFuture.get()) // It should return the published message id.MyCFC cfcObj = new MyCFC()
messageMetadata = {
data: serializeAVRO(cfcObj, schema),
attributes: {
"attribute1" : "value1",
"attribute2" : "value2"
}
}
publishedFuture = topic.publish(messageMetadata)
WriteDump(publishedFuture.get()) // It should return the published message id.MyCFC cfcObj = new MyCFC()
messageMetadata = {
data: serializeProtoBuf(cfcObj, schema),
attributes: {
"attribute1" : "value1",
"attribute2" : "value2"
}
}
publishedFuture = topic.publish(messageMetadata)
WriteDump(publishedFuture.get()) // It should return the published message id.<cfscript>
gcpCred = {
vendorName: "GCP",
alias: "gcp_cred_alias" // This alias must be defined in the CF Administrator.
}
pubsubConfig = {
alias: "PubSubOne",
serviceName: "PUBSUB",
publisherSettings: {
batchingSettings: {
enable: true, // default: false
elementCountThreshold : 1, // default: 100 messages
requestByteThreshold : 50, // default: 1000 bytes
delayThreshold : "100m" // default: 1 milliseconds
}
}
};
pubsub = getCloudService(gcpCred, pubsubConf)
myTopic = pubsub.getTopic("myTopic")
messageMetadata = {
"data" : "Hello World!!"
}
publishedFuture = topic.publish(messageMetadata)
WriteDump(publishedFuture.get()) // It should return the published message id.
</cfscript><cfscript>
gcpCred = {
vendorName:"GCP",
alias: "gcp_cred_alias" // This alias must be defined in the CF Administrator.
}
pubsubConfig = {
alias: "PubSubOne",
serviceName: "PUBSUB",
publisherSettings: {
executorProvider: {
threadCount: 4,
threadNamePrefix: "cf-pubsub-thread"
}
}
}
pubsub = getCloudService(gcpCred, pubsubConf)
topic = pubsub.getTopic("myTopic")
messageMetadata = {
"data" : "Hello"
}
publishedFuture = topic.publish(messageMetadata)
WriteDump(publishedFuture.get()) // It should return the published message id.
</cfscript><cfscript>
gcpCred = {
vendorName: "GCP",
alias: "gcp_cred_alias" // This alias must be defined in the CF Administrator.
}
pubsubConf = {
alias: "pubsub_conf_alias",
serviceName: "PUBSUB"
}
pubsub = cloudService(gcpCred, pubsubConf)
topic = pubsub.getTopic("myTopic")
messageMetadata = {
message: {
data: "Hello World 12345!",
attributes: {
author : "Martin Fowler",
year : 2014
}
}
}
publishedFuture = topic.publish(messageMetadata)
WriteDump(publishedFuture.get()) // It should return the published message id.
</cfscript><cfscript>
gcpCred = {
vendorName:"GCP",
alias: "gcp_cred_alias" // This alias must be defined in the CF Administrator.
}
pubsubConfig = {
alias: "PubSubOne",
serviceName: "PUBSUB",
publisherSettings: {
batchingSettings: {
enable: true,
elementCountThreshold: 1, // default: 100 messages
requestByteThreshold: 50, // default: 1000 bytes
delayThreshold: "100m", // default: 1 milliseconds
flowControlSettings: {
maxOutstandingRequestBytes : 10240,
maxOutstandingElementCount : 100,
limitExceededBehavior : "Block" // Supported values: Block, Ignore, ThrowException
}
}
}
}
pubsub = getCloudService(gcpCred,pubsubConf)
topic = pubsub.getTopic("myTopic")
messageMetadata = {
message: {
data : "Hello World 12345!",
attributes : {
author : "Martin Fowler",
year : 2014
}
}
}
publishedFuture = topic.publish(messageMetadata)
WriteDump(publishedFuture.get()) // It should return the published message id.
</cfscript><cfscript>
gcpCred = {
vendorName:"GCP",
alias: "gcp_cred_alias" // This alias must be defined in the CF Administrator.
}
pubsubConfig = {
alias: "PubSubOne",
serviceName: "PUBSUB",
publisherSettings: {
endpoint: "asia-northeast1-pubsub.googleapis.com:443",
enableMessageOrdering: "true"
}
}
pubsub = getCloudService(gcpCred, pubsubConf)
topic = pubsub.getTopic("myTopic")
messageMetadata = {
message: {
data: "Hello World 12345!",
orderingKey: "NamingFilter"
}
}
publishedFuture = topic.publish(messageMetadata)
WriteDump(publishedFuture.get()) // It should return the published message id.
</cfscript><cfscript>
gcpCred = {
vendorName:"GCP",
alias: "gcp_cred_alias" // This alias must be defined in the CF Administrator.
}
pubsubConfig = {
alias: "PubSubOne",
serviceName: "PUBSUB",
publisherSettings: {
retrySettings: {
initialRetryDelay. : "100m", // default: 100 ms
initialRpcTimeout : "5s", // default: 5 seconds
maxAttempts : 5, // default: 0
maxRetryDelay : "60s", // default : 60 seconds
maxRpcTimeout : "10M", // default: 600 seconds
maxDelayMultiplier : 2, // back off for repeated failures, default: 1.3
rpcTimeoutMultiplier : 1, // default: 1.0
totalTimeout : "10M" // default: 600 seconds
}
}
}
pubsub = getCloudService(gcpCred,pubsubConfing)
topic = pubsub.getTopic("myTopic")
messageMetadata = {
"messages" : [{
data : "Hello World!"
}]
}
publishedFuture = topic.publish(messageMetadata)
WriteDump(publishedFuture.get()) // It should return the published message id.
</cfscript>publishAllOutstanding(topicName)| Parameter | Description | Required |
| topicName | The name of the topic. | Yes |
<cfscript>
cred = {
projectId : “<your project id>“,
credentialJsonFilePath : “<path to your credentials json file>”
}
conf = {
serviceName : “pubsub”
}
pubsubclient = getCloudService(cred, conf)
response = pubsubclient.publishAllOutstanding(“myTopic”)
WriteDump(response)
</cfscript>createSnapshot(snapshotAttributes)| Parameter | Description | Required |
| snapshotName | Name of the snapshot to be created. | Yes |
| subscriptionName | Name of the subscription. | Yes |
<cfscript>
cred = {
projectId : "<your project id>",
credentialJsonFilePath : "<path to your credentials json file>"
}
conf = {
serviceName : "pubsub"
}
pubsubclient=getCloudService(cred, conf)
topicName = "myTopic"
topic = pubsubClient.createTopic(topicName)
subName="mysubscription"
subscriptionMetadata = {
"subscriptionName" : subName
}
// create the subscription
topic.subscribe(subscriptionMetadata)
// create the snapshot
snapshotName="snshot-01"
snapshotAttributes = {
snapshotName: snapshotName,
subscriptionName: subName,
labels : {
name : "wrench",
mass : "13kg",
createdtime : dateTimeFormat(now(), "hh-nn_mm-dd-yyyy"),
emptykey : ""
}
}
snapshotResponse=pubsubClient.createSnapshot(snapshotAttributes)
</cfscript>getSnapshot(snapshotName)Parameter | Description | Required |
snapshotName | Name of the snapshot whose details are to be retrieved. | Yes |
<cfscript>
cred = {
projectId : "my-gcp-project",
credentialJsonFilePath : "path of creds json file"
};
conf = {
serviceName : "pubsub"
};
pubsubclient=getCloudService(cred, conf)
topicName = "topic-ss-02"
// create the topic
topic = pubsubClient.createTopic(topicName)
subName="sub-name-ss-02"
subscriptionMetadata = {
"subscriptionName" : subName
}
// create the subscription
topic.subscribe(subscriptionMetadata)
// create the snapshot
snapshotName="snshot-02"
snapshotAttributes = {
snapshotName: snapshotName,
subscriptionName: subName,
labels : {
name : "wrench",
mass : "13kg",
createdtime : dateTimeFormat(now(), "hh-nn_mm-dd-yyyy"),
emptykey : ""
}
}
// create a snapshot
pubsubClient.createSnapshot(snapshotAttributes)
// get the snapshot
getResponse=pubsubClient.getSnapshot(snapshotName)
writeDump(getResponse)
</cfscript>updateSnapshot(updatedSnapshotAttributes)<cfscript>
cred = {
projectId : "my-gcp-project",
credentialJsonFilePath : "C:\GCP-keys\my-gcp-project-ab38bee5f1e0.json"
};
conf = {
serviceName : "pubsub"
};
pubsubclient=getCloudService(cred, conf)
topicName="topic-update-ss01"
// create the topic
topic = pubsubClient.createTopic(topicName)
subName="subupdate-ss01"
subscriptionMetadata = {
"subscriptionName" : subName
}
// create the subscription
topic.subscribe(subscriptionMetadata)
// create the snapshot
snapshotName="snshot-ss-01"
snapshotAttributes = {
snapshotName: snapshotName,
subscriptionName: subName,
labels : {
name : "wrench",
mass : "13kg",
createdtime : dateTimeFormat(now(), "hh-nn_mm-dd-yyyy"),
emptykey : ""
}
}
// create a snapshot
pubsubClient.createSnapshot(snapshotAttributes)
updatedSnaphotAttributes={
snapshotName: snapshotName,
subscriptionName: subName,
labels : {
name : "shovel",
mass : "5kg",
createdtime : dateTimeFormat(now(), "hh-nn_mm-dd-yyyy"),
emptykey : ""
}
}
// update the snapshot
pubsubClient.updateSnapshot(updatedSnaphotAttributes)
writeOutput("Snapshot " & snapshotName & " updated succcessfully")
</cfscript>listSnapshots()Parameter | Description |
nextPageToken | Retrieve the next page of results and perform the same request. |
<cfscript>
cred = {
projectId : "my-gcp-project",
credentialJsonFilePath : "C:\GCP-keys\my-gcp-project-ab38bee5f1e0.json"
}
conf = {
serviceName : "pubsub"
}
pubsubclient=getCloudService(cred, conf)
listResponse=pubsubclient.listSnapshots()
writeDump(listResponse)
</cfscript>deleteSnapshot(snapshotName)Parameter | Description |
snapshotName | Name of the snapshot to be deleted. |
<cfscript>
cred = {
projectId : "my-gcp-project",
credentialJsonFilePath : "C:\GCP-keys\my-gcp-project-ab38bee5f1e0.json"
};
conf = {
serviceName : "pubsub"
};
pubsubclient=getCloudService(cred, conf)
topicName = "topic-ss-delete"
// create the topic
topic = pubsubClient.createTopic(topicName)
subName="sub-name-ss-delete"
subscriptionMetadata = {
"subscriptionName" : subName
}
// create the subscription
topic.subscribe(subscriptionMetadata)
// create the snapshot
snapshotName="snshot-delete"
snapshotAttributes = {
snapshotName: snapshotName,
subscriptionName: subName,
labels : {
name : "wrench",
mass : "13kg",
createdtime : dateTimeFormat(now(), "hh-nn_mm-dd-yyyy"),
emptykey : ""
}
}
// create a snapshot
pubsubClient.createSnapshot(snapshotAttributes)
// delete the snapshot
pubsubClient.deleteSnapshot(snapshotName)
writeOutput("Snapshot deleted successfully")
</cfscript>seekMessages(requestParameters)Parameter | Description | Required |
snapshotName | Name of the snapshot. | Yes |
subscriptionName | Name of the subscription. | Yes |
timeStamp | Timestamp of the snapshot. | No |
<cfscript>
cred = {
projectId : "adbe-gcp0318",
credentialJsonFilePath : "C:\GCP-keys\adbe-gcp0318-ab38bee5f1e0.json"
};
conf = {
serviceName : "pubsub"
};
pubSubClient=getCloudService(cred,conf)
// set names
topicName = "topic-ss-seek"
subName = "sub_ss";
snapshotName="snapshot_ss"
// create a topic
topic = pubsubClient.createTopic(topicName)
subscriptionMetadata = {
"subscriptionName" : "#subName#",
"topicName" : "#topicName#"
}
// subscribe to the topic
subscription = topic.subscribe(subscriptionMetadata)
// create a snapshot
snapshot = pubsubClient.createSnapshot({
snapshotName: snapshotName,
subscriptionName: subName
})
writeOutput("seeking to snapshot.. replaying msgs.<hr>")
snapshotID=snapshot.getID()
seekAttributes = {
subName,
snapshotID
}
seekResponse = pubsubClient.seekMessages(seekAttributes)
writeDump(seekAttributes)
</cfscript>setIAMolicy(subscriptionPolicyMetadata)Parameter | Description |
resourceName | Name of the subscription. |
resourceType | Valid values are:
|
bindings | Specify the role and email of the members who can add an IAM policy. Valid values for role are:
|
<cfscript>
cred = {
projectId : "my-gcp-project",
credentialJsonFilePath : "C:\GCP-keys\my-gcp-project-ab38bee5f1e0.json"
};
conf = {
serviceName : "pubsub"
};
pubsubclient=getCloudService(cred, conf)
topicName="topic-add-iam"
// create the topic
topic = pubsubClient.createTopic(topicName)
// create the subscription
subName="sub-add-iam"
subscriptionMetadata = {
"subscriptionName" : subName
}
topic.subscribe(subscriptionMetadata)
// add IAM Policy
addIamPolicy = {
resourceName : subscriptionName,
resourceType : "Subscription",
bindings : {
role : "roles/viewer",
members : ["user:user@example.com"]
}
}
pubsubClient.addIAMPolicy(addIamPolicy)
writeOutput("IAM policy added successfully")
</cfscript>setIAMPolicy(policyStruct)| Parameter | Description | Required |
| subName | Name of the subscription for which IAM policy needs to be set. | Yes |
<cfscript>
this.gcpCred = {
"vendorName":"GCP",
"alias": "gcp_cred_alias",
"projectid": "{ProjectID}"
}
this.pubsubConf = {
"alias":"pubsub_conf_alias",
"serviceName" : "PUBSUB",
}
pubsub = cloudService(this.gcpCred, this.pubsubConf)
// Create new role > members binding and update the topic policy
topicPolicyMetadata = {
"resource" : "topicName",
"policy" : "oldPolicy",
"bindings" : {
"role" : "roles/pubsub.editor",
"members" : "allUsers",
"conditions" : ""
}
}
// set the IAM policy
pubsub.setIAMPolicy(topicPolicyMetadata)
// retrieve the IAP policy
pubsub.getIAMPolicy("topicName")
</cfscript>getIAMPolicy(policyStruct)| Parameter | Description | Required |
| resourceName | The name of the subscription. | Yes |
| resourceType | Topic or subscription. | Yes |
| policyOptions | Struct of options | Yes |
<cscript>
cred = {
projectId : "<your project id>",
credentialJsonFilePath : "<path to your credentials json file>"
}
conf = {
serviceName : "pubsub"
}
pubsubclient=getCloudService(cred, conf)
topicName = "topic-add-policy"
subscriptionName = "sub-#topicName#"
topic = pubsubClient.createTopic(topicName)
subscriptionAttributes = {
subscriptionName : "#subscriptionName#",
topicName : "#topicName#"
}
subscription = topic.subscribe(subscriptionAttributes)
policyMapV1 = {
version = "1",
resourceName : subscriptionName,
resourceType : "Subscription",
binding : [{
ROLE : "roles/editor",
MEMBERS : ["user:pn@adb.com"]
},
{
ROLE : "roles/owner",
MEMBERS : ["user:pn@adb.com"]
},
{
ROLE : "roles/viewer",
MEMBERS : ["user:mj@adb.com","user:pn@adb.com"]
}]
}
setIAMPolicy = pubsubClient.setIAMPolicy(policyMapV1)
cfdump(var=#setIAMPolicy#, label="set policy")
iAMPolicy = pubsubClient.getIAMPolicy({
resourceName : subscriptionName,
resourceType : "Subscription",
policyOptions : {
requestedPolicyVersion : policyMapV1[VERSION]
}
})
cfdump(var=#iAMPolicy#, label="get policy")
</cfscript>testIAMPermissions(parameterStruct)| Parameter | Description | Required |
| resourceName | The name of the subscription. | Yes |
| resourceType | Topic or subscription. | Yes |
| permissions | The set of permissions to check for the resource. | Yes |
<cfscript>
cred = {
projectId : "<your project id>",
credentialJsonFilePath : "<path to your credentials json file>"
}
conf = {
serviceName : "pubsub"
}
pubsubclient=getCloudService(cred, conf)
topicName = "topic-add-policy"
subscriptionName = "sub-#topicName#"
topic = pubsubClient.createTopic(topicName)
subscriptionAttributes = {
subscriptionName : "#subscriptionName#",
topicName : "#topicName#"
}
subscription = topic.subscribe(subscriptionAttributes)
policyMapV1 = {
version = "1",
resourceName : subscriptionName,
resourceType : "Subscription",
binding : [{
ROLE : "roles/editor",
MEMBERS : ["user:pn@example.com"]
},
{
ROLE : "roles/owner",
MEMBERS : ["user:pn@example.com"]
},
{
ROLE : "roles/viewer",
MEMBERS : ["user:mj@example.com","user:pn@example.com"]
}]
}
setIAMPolicy = pubsubClient.setIAMPolicy(policyMapV1)
cfdump(var=#setIAMPolicy#, label="set policy")
iAMPolicy = pubsubClient.getIAMPolicy({
resourceName : subscriptionName,
resourceType : "Subscription",
policyOptions : {
requestedPolicyVersion : policyMapV1[VERSION]
}
})
cfdump(var=#iAMPolicy#, label="get policy")
addIamPolicy = {
resourceName : "#subName#",,
resourceType : "Subscription",
bindings : {
role : "roles/editor",
members : ["user:mj@adb.com"]
}
}
iAMPolicy = pubsubClient.addIAMPolicy(addIamPolicy);
cfdump(var=#iAMPolicy#, label="add policy")
testIAMPermissions = {
resourceName : "#subName#",
resourceType : "Subscription",
permissions : ["pubsub.topics.attachSubscription", "pubsub.topics.publish", "pubsub.topics.update"]
}
permissions = pubsubClient.testIAMPermissions(testIAMPermissions);
WriteDump(permissions);
</cfscript>pullMessages(structMetadata)| Parameter | Description | Required |
| subscriptionName | Name of the subscription. | Yes |
| maxMessages | The maximum amount of messages to pull. | Yes |
| returnImmediately | Returns te messages immediately even if the subscription doesn't contain enough messages to satisfy maxMessages. | No |
<cfscript>
cred = {
projectId : "<your project id>",
credentialJsonFilePath : "<path to your credentials json file>"
}
conf = {
serviceName : "pubsub"
}
pubsubclient = getCloudService(cred, conf)
topic = pubsubclient.getTopic("myTopic")
subscription = topic.getSubscription("mySubscription”)
pullMessageMetadata = {
maxMessages: 100
}
pullMsgResponse = subscription.pullMessages(pullMessageMetadata)
for(message in pullMsgResponse.messages) {
WriteOutput(message.ackId)
WriteOutput(message.messageId)
WriteOutput(message.data)
WriteOutput(message.publishTime)
</cfscript>acknowledgeMessages(acknowledgeMetadata) | Parameter | Description | Required |
| subscriptionName | The name of the subscription. | Yes |
| ackIds | Array of acknowledgement Ids. | Yes |
<cfscript>
cred = {
projectId : "<your project id>",
credentialJsonFilePath : "<path to your credentials json file>"
}
conf = {
serviceName : "pubsub"
}
pubsubclient = getCloudService(cred, conf)
topic = pubsubclient.getTopic("myTopic")
subscription = topic.getSubscription(“mySubscription”)
pullMessageMetadata = {
maxMessages: 100
}
pullMsgResponse = subscription.pullMessages(pullMessageMetadata)
ackIds = arrayNew(1)
for(message in pullMsgResponse.messages) {
ackId = message.ackId
ackIds.append(ackId)
WriteOutput(ackId)
WriteOutput(message.messageId)
WriteOutput(message.data)
WriteOutput(message.publishTime)
}
acknowledgeMessageMetadata = {
ackIds: ackIds
}
ackMsgResponse = subscription.acknowledgeMessages(acknowledgeMessageMetadata)
writeDump(ackMsgResponse)
</cfscript>| Parameter | Required | Description |
| subscriptionName | The name of the subscription. | Yes |
| ackIds | Array of acknowledgement Ids. | Yes |
| ackDeadlineSeconds | The time within which the acknowledgement expires. | Yes |
<cfscript>
cred = {
projectId : "<your project id>"
credentialJsonFilePath : "<path to your credentials json file>"
}
conf = {
serviceName : "pubsub"
}
pubsubclient = getCloudService(cred, conf)
topic = pubsubclient.getTopic("myTopic")
subscription = topic.getSubscription("mySubscription")
pullMessageMetadata = {
maxMessages: 100
}
pullMsgResponse = subscription.pullMessages(pullMessageMetadata)
ackIds = arrayNew(1)
for(message in pullMsgResponse.messages) {
ackId = message.ackId
ackIds.append(ackId)
WriteOutput(ackId)
WriteOutput(message.messageId)
WriteOutput(message.data)
WriteOutput(message.publishTime)
}
modifyAckDeadlineMetadata = {
ackIds: ackIds,
ackDeadlineSeconds: 80
}
WriteDump(subscription.modifyAckDeadline(modifyAckDeadlineMetadata));
acknowledgeMessageMetadata = {
ackIds: ackIds
}
ackMsgResponse = subscription.acknowledgeMessages(acknowledgeMessageMetadata)
writeDump(ackMsgResponse)
</cfscript>createSchema(schemaStruct)| Parameter | Description | Required |
| schemaName | The name of the schema for Avro and Protobuf. | Yes |
| type | The valid values are: Avro or Protobuf. | Yes |
| definition | The schema definition. You can pass the definition directly. | Yes |
<cfscript>
cred = {
projectId : "<your project id>",
credentialJsonFilePath : "<path to your credentials json file>"
}
conf = {
serviceName : "pubsub"
}
pubsubclient=getCloudService(cred, conf)
schemaName = "schemaOne"
schemaMetadata = {
schemaName: schemaName,
type: "protocol_Buffer",
Definition: 'syntax = "proto2"; message ProtocolBuffer {required string name = 1;}'
}
createResponse=pubsubClient.createSchema(schemaMetadata)
writeDump(createResponse)
</cfscript>getSchema(schemaName)<cfscript>
cred = {
projectId : "<your project id>",
credentialJsonFilePath : "<path to your credentials json file>"
}
conf = {
serviceName : "pubsub"
}
pubsubclient=getCloudService(cred, conf)
schemaName = "schemaOne"
schemaMetadata = {
schemaName: schemaName,
type: "protocol_Buffer",
Definition: 'syntax = "proto2"; message ProtocolBuffer {required string name = 1;}'
}
createResponse=pubsubClient.createSchema(schemaMetadata)
createResponse=pubsubClient.createSchema(schemaMetadata)
writeDump(createResponse)
schema = pubsubClient.getSchema(schemaName)
writeOutput("schema ID: " & schema.getID() & "<br>")
writeOutput("schema Name: " & schema.getName() & "<br>")
writeOutput("schema type: " & schema.getType() & "<br>")
writeOutput("schema Definition: " & schema.getDefinition() & "<br>")
</cfscript>listSchemas()listSchemas(parameterStruct)| Parameter | Description | Required |
| pageSize | Number of schemas to be displayed. | Yes |
| nextPageToken | Token used to access the next page of this result. | Yes |
| schemaView | Valid values are: Full or Basic | Yes |
<cfscript>
cred = {
projectId : "<your project id>",
credentialJsonFilePath : "<path to your credentials json file>"
}
conf = {
serviceName : "pubsub"
}
pubsubclient=getCloudService(cred, conf)
schemaName = "schemaOne"
schemaMetadata = {
schemaName: schemaName,
type: "protocol_Buffer",
Definition: 'syntax = "proto2"; message ProtocolBuffer {required string name = 1;}'
}
pubsubClient.createSchema(schemaMetadata)
schema = pubsubClient.getSchema(schemaName)
first2schemas = pubsubClient.listSchemas({
pageSize: 2,
schemaView : "full"
})
writeDump(first2schemas)
</cfscript>deleteSchema(schemaName)<cfscript>
cred = {
projectId : "<your project id>",
credentialJsonFilePath : "<path to your credentials json file>"
}
conf = {
serviceName : "pubsub"
}
pubsubclient=getCloudService(cred, conf)
schemaName = "schemaOne"
schemaMetadata = {
schemaName: schemaName,
type: "protocol_Buffer",
Definition: 'syntax = "proto2"; message ProtocolBuffer {required string name = 1;}'
}
pubsubClient.createSchema(schemaMetadata)
deleteResponse=pubsubClient.deleteSchema(schemaName)
writeDump(deleteResponse)
</cfscript>validateSchema(schemaMetadata)| Parameter | Description | Required |
| schemaName | The name of the schema. | Yes |
| type | AVRO or Protobuf | Yes |
| definition | The schema definition. | Yes |
<cfscript>
cred = {
projectId : "<your project id>",
credentialJsonFilePath : "<path to your credentials json file>"
}
conf = {
serviceName : "pubsub"
}
pubsubclient = getCloudService(cred, conf)
schemaMetadata = {
schemaName: "mySchema",
type: “AVRO”,
definition: ‘{
"type" : "record",
"name" : "Avro",
"fields" : [ {
"name" : "StringField”,
"type" : “string”
}, {
"name" : "IntField",
"type" : "int"
} ]
}’
}
schema = pubsubclient.validateSchema(schemaMetadata);
WriteDump(schema);
</cfscript>validateMessage(validateMetadata)| Parameter | Description | Required |
| schemaName | The name of the schema. | Yes |
| schemaEncoding | JSON or Binary | Yes |
| data | The data to validate. | Yes |
<cfscript>
cred = {
projectId : "<your project id>",
credentialJsonFilePath : "<path to your credentials json file>"
}
conf = {
serviceName : "pubsub"
}
pubsubclient = getCloudService(cred, conf)
validateMessageMetadata = {
schemaName: "mySchema",
schemaEncoding: "JSON",
data: ‘{ "name" : "charlie"}’
}
schema = pubsubclient.validateMessage(validateMessageMetadata);
WriteDump(schema);
</cfscript>