Where to receive watch notifications for gmail in .NET? - c#

I'm trying to receive watch notification for Gmail mailboxes in my .NET C# program.
I have the following code:
WatchRequest body = new WatchRequest()
{
LabelIds = labelIds,
TopicName = PrivateKeys.GoogleGmailTopic
};
WatchResponse response = new UsersResource.WatchRequest(_gmailService, body, "me")
{
Key = PrivateKeys.GoogleApiKey,
OauthToken = AccessToken
}
.Execute();
... and it seems to work, since I get a response.
But where do I receive these notifications inside my program? How can I configure the event entry point?

Assuming you did the preliminary work to set up a Cloud Pub/Sub client (described here: https://developers.google.com/gmail/api/guides/push#initial_cloud_pubsub_setup), you should have a Pub/Sub subscription - either PULL or PUSH.
In order to get the notifications, your application should initiate a subscriber, you can follow the instructions in https://cloud.google.com/pubsub/docs/pull for PULL or in https://cloud.google.com/pubsub/docs/push for PUSH. Configuring the event entry point should be done as part of the subscriber set up.

Related

How to subscribe to updates in Telegram Api?

My question is a copy of this question
However, I don't understand how to use the answer given there
The library I am using already implements what the answer says
TelegramClient.cs
var config = new TLRequestGetConfig();
var request = new TLRequestInitConnection()
{
ApiId = apiId,
AppVersion = "1.0.0",
DeviceModel = "PC",
LangCode = "en",
Query = config,
SystemVersion = "Win 10.0",
SystemLangCode = "en",
LangPack = ""
};
var invokewithLayer = new TLRequestInvokeWithLayer() { Layer = 108, Query = request };
await sender.Send(invokewithLayer, token).ConfigureAwait(false);
await sender.Receive(invokewithLayer, token).ConfigureAwait(false);
dcOptions = ((TLConfig)invokewithLayer.Response).DcOptions.ToList();
Where does Telegram send updates?
I thought the updates could be read in the TcpClient that the TelegramClient has, but no, it doesn't receive updates
The documentation says:
Update events are sent to an authorized user into the last active
connection (except for connections needed for downloading / uploading
files).
So to start receiving updates the client needs to init
connection and call API method, e.g. to fetch current state.
But where does it send updates? How do I subscribe to them / how do I read them?
P.S. updates.getDifference is not what i'm looking for
UPD
I've already looked at all the source code, but the most I found is processMessage in MtProtoSender, but it only handles manually sent requests
Another library based on TDLib handles incoming updates. Trying to understand how it does it, I got to this point. What is going on here and how can I do the same in TLSharp I do not understand
Same problem in another library which was solved but doesn't work for me

Configuring wildcard topic selectors in ActiveMQ

Based on the documentation wildcards support does exist, but I can't seem to find any other info on whether it's just supposed to work or if it's configured on the server or whether the producers or consumers need to configure it.
I'm assuming as a publisher I would just send messages to a topic named /patient/2/goal/ and when a consumer subscribed to a topic called /patient/*/goal/ it would still receive the message, however nothing shows up. What am I missing?
Please note that if I publish a message to /patient/*/goal/ and subscribe to /patient/*/goal/ then I receive the message. However, that only confirms my message bus is working, not that wildcard support is working.
Producer test:
var connectUri = new Uri("...");
var factory = new NMSConnectionFactory(connectUri);
var connection = factory.CreateConnection();
session = connection.CreateSession();
var destination = session.GetTopic("/patient/1/goal/");
producer = session.CreateProducer(destination);
...
Consumer:
var topic = _session.GetTopic("/patient/*/goal/");
var consumer = _session.CreateConsumer(topic);
...
Using / as the the path separator needs to be configured through a plugin. Switching to . made it work as expected.

Can we filter messages from Amazon SQS queue by message attributes?

For now I have tried to filter the messages based on Message Attribute Name="Class". As you can see in the below code
//Specify attribute list
List<string> AttributesList = new List<string>();
AttributesList.Add("Class");
receiveMessageRequest.MessageAttributeNames = AttributesList;
receiveMessageRequest.QueueUrl = urlSQS;
receiveMessageRequest.MaxNumberOfMessages = 10;
ReceiveMessageResponse receiveMessageResponse = objClient.ReceiveMessage(receiveMessageRequest);
But the messages are not been filtered based on the provided MessageAttributeName = "class".
receiveMessageRequest.MessageAttributeNames = AttributesList;
This tells SQS which message attributes you want it to return with the message if the are present on the message. It is not a message filter. If the attributes aren't present, nothing happens.
But your confusion seems understandable -- it's not actually obvious why the API even has this functionality, though it may be a holdover from when SQS supported only smaller messages than it does today, or it may be so that you can avoid spending any time parsing information from the response that you will end up discarding. I almost always just ask for All.
Please note this regarding messaging services on AWS
SQS : No filtering support ( while picking up messages)
SNS : Supports attributes-based filtering: subscriber can set a subscription attribute (a subscription filter policy) which is applied on incoming messages and only relevant messages can be sent to the subscriber.
EventBridge: Amazon EventBridge supports declarative filtering using event patterns. With event pattern content filtering you can write complex rules that only trigger under very specific conditions. For instance, you might want a rule that will trigger only when a field of the event is within a specific numeric range, if the event comes from a specific IP address, or only if a specific field does not exist in the event JSON.
Please refer my article for a detailed difference between main messaging frameworks on AWS.
https://www.linkedin.com/pulse/mastering-art-decoupling-application-architecture-aws-amit-meena/
It depends on how the message in question gets onto the queue. If you are pushing the message via SNS then yes you can filtered messages; https://docs.aws.amazon.com/sns/latest/dg/message-filtering.html
Any other filtering mechanism doesn't exist right now.
Hope that helps!
As per the AWS SDK method, we can use following code to do the filter.
ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest("QUEUE URL" );
receiveMessageRequest.setMaxNumberOfMessages(Integer.valueOf(1));
private static AmazonSQS sqs;
List<Message> messages = sqs.receiveMessage(receiveMessageRequest.withMessageAttributeNames("Attribute Name")).getMessages();
If you want all the message then use given code
ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest("QUEUE URL" );
receiveMessageRequest.setMaxNumberOfMessages(Integer.valueOf(1));
private static AmazonSQS sqs;
List<Message> messages = sqs.receiveMessage(receiveMessageRequest.withMessageAttributeNames("All")).getMessages();

Send message to Azure ServiceBus when items have changed in a Sharepoint List

I'd like to send message to an Azure ServiceBus queue when some items have changed inside a SharePoint list. When you upload/delete a file, I need to create an event that enqueue a message in Azure Service Bus with the content of the file and the id. I don't know how to create an event that do that, Can someone point to me some articles, tutorial to start.
you are looking for event receiver:
How to: Create an Event Receiver
By creating event receivers, you can respond when a user interacts with SharePoint items such as lists or list items. For example, the code in an event receiver can be triggered when a user changes the calendar or deletes a name from a contacts list.
Sample code from the documentation:
public override void ItemAdded(SPItemEventProperties properties)
{
properties.ListItem["Patient Name"] = "Scott Brown";
properties.ListItem.Update();
base.ItemAdded(properties);
}
Now you need to change this code to send message to a servicebus queue:
Get started with Service Bus Queues
public override void ItemAdded(SPItemEventProperties properties)
{
var connectionString = "<Your connection string>";
var queueName = "<Your queue name>";
var client = QueueClient.CreateFromConnectionString(connectionString, queueName);
var message = new BrokeredMessage("This is a test message!");
client.Send(message);
base.ItemAdded(properties);
}
If you need to send the content of the file, just keep in mind tihs:
Service Bus queues support a maximum message size of 256 Kb (the header, which includes the standard and custom application properties, can have a maximum size of 64 Kb).
So you may need to store your file into a blob storage and just send a message to the queue with the id of the create blob also.
Get started with Azure Blob storage using .NET

ServiceStack event for client disconnect

I'm experimenting with ServiceStack's Server Events feature and want to make a sort of "online users" test app. The idea is I want to update each user that connects to a channel "Users" whenever a new user joins or leaves. The problem is I cannot find a way to detect when a subscription/user leaves/disconnects.
The ServerEventsClient.OnCommand callback is fired when a User Joins, Leaves or Updates their ServerEvent subscription.
You can also fetch a list of all active subscribers from a channel at anytime with:
var sseClient = new ServerEventsClient(...);
var response = sseClient.ServiceClient.Get(new GetEventSubscribers {
Channels = sseClient.Channels
});
Which will return a List of untyped Dictionary<string,string> containing the subscribers public info.
I've also just added a Typed API for GetChannelSubscribers() in this commit that's now available from v4.0.57 on MyGet which provides a Typed API to fetch all users subscribed to the ServerEventsClient channels, e.g:
var channelSubscribers = sseClient.GetChannelSubscribers();

Categories

Resources