Signal R # Adding User Group at Initialize Level? - signalr

Hello all how we can add user group when we are establish the connection.
I m using https://cdn.jsdelivr.net/npm/#microsoft/signalr#3.1.8/dist/browser/signalr.min.js Library
I m initializing connection with below code #
let hubConnection = new signalR.HubConnectionBuilder()
.withUrl(hubUrl)
.configureLogging(signalR.LogLevel.Information)
.build();
now what I need as any Client try to create connection with my Hub with above code it will be going to be part
of one my group I don't want to after Initialization?
so at initialize level or opening connection I want group to be assigned to Client.
any though

Related

Receive service bus message queue/topics in web api

I am working on a microservice based application in azure. My requirement is I had a service bus and I need to consume that service bus message in web api. Currently I implemented through azure functions, but my company asked to use api. Is it possible?, If possible please show me how to do it
You can create Background service to listen to message from service bus queue.
Below are few key points that needs to be noted:
Background task that runs on a timer.
Hosted service that activates a scoped service. The scoped service can use dependency injection (DI).
Queued background tasks that run sequentially.
App Settings:
1. {
2. "AppSettings": {
3. "QueueConnectionString": "<replace your RootManageSharedAccessKey here>",
4. "QueueName": "order-queue"
5. }
6. }
You can refer to c-sharpcorner blog for step by step process.
There is a simple way to get a simple message.
ServiceBusClient client = new ServiceBusClient("Endpoint=sb://yourservicesbusnamespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=Your_SharedAccess");
var receiver = client.CreateReceiver("Your Queue");
var message = await receiver.ReceiveMessagesAsync(1);
string ascii = Encoding.ASCII.GetString(message.FirstOrDefault().Body);
Console.WriteLine("Received Single Message: " + ascii);
await receiver.CompleteMessageAsync(message.FirstOrDefault());
I did some modifications from this post
https://ciaranodonnell.dev/posts/receiving-from-azure-servicebus/

Set TraceId on Activity

I have a worker service which listens on a message broker and gets triggered when a message arrives. Once it is triggered I manually create an Activity and copy SpanId from the incoming message into the local Activity.ParentID. However, the local Trace Id is generated anew and I lose the ability to trace across services. I cannot manually copy the Trace Id over because Activity.TraceId is read only.
Activity.DefaultIdFormat = ActivityIdFormat.W3C;
using var activity = new Activity("Consumer");
activity.SetParentId(messageFromBroker.ParentId);
activity.Start();
_logger.LogInformation("foo foo foo");
// ... do some processing...
activity.Stop();
How can I create a new Activity and manually set TraceId?
It seems TraceId cannot be set explicitly, but what you can do is provide entire traceparent header, as below:
activity.SetParentId("00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01");

Out of Memory due to multiple consumers ActiveMQ

I am using DefaultMessageListenerContainer as below :
private static final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MessageConsumer.class);
public static final DefaultMessageListenerContainer container = context.getBean(DefaultMessageListenerContainer.class);
For a given queue that my listener listens to , the first time my program runs it starts the listener .... and this creates a Consumer for the queue that I can see in the Active MQ Console.
The problem I have is every time I checkin some new code, there is another new Consumer created for the queue and the old one is still hanging on creating some Out of Memory issue.
What am I doing wrong here? How do I make sure there is only 1 consumer and the old consumer is killed with every new code checkin? Hope I explained the issue clearly.

firebase onDisconnect() is not fired when user lose connection

Hello React native community, I'm trying to use onDisconnect() in firebase but the problem is that the void isn't getting fired when the network loses its connection but it is working if I close the app or when the app crashes.
This code is working if Wi-Fi is on but it's not working at all if Wi-Fi is off..
firebase.database().ref('users/test/connected').onDisconnect().set(false)
Any ideas?
You can combine disconnect operations with connection status monitoring and server time stamps to build a user connection status system. On this system, each user stores data in a specific database location to alert the real-time database client to online. The client sets this location to true when it comes online and to time stamp when it disconnects. This timestamp indicates the last time the user was online.
Apps have a disconnect operation ahead of the user's online display, so that there is no contention if the client loses network connectivity before the two commands are sent to the server.
// since I can connect from multiple devices or browser tabs, we store each connection instance separately
// any time that connectionsRef's value is null (i.e. has no children) I am offline
var myConnectionsRef = firebase.database().ref('users/test/connections');
// stores the timestamp of my last disconnect (the last time I was seen online)
var lastOnlineRef = firebase.database().ref('users/test/lastOnline');
var connectedRef = firebase.database().ref('.info/connected');
connectedRef.on('value', function(snap) {
if (snap.val() === true) {
// We're connected (or reconnected)! Do anything here that should happen only if online (or on reconnect)
var con = myConnectionsRef.push();
// When I disconnect, remove this device
con.onDisconnect().remove();
// Add this device to my connections list
// this value could contain info about the device or a timestamp too
con.set(true);
// When I disconnect, update the last time I was seen online
lastOnlineRef.onDisconnect().set(firebase.database.ServerValue.TIMESTAMP);
}
});

Listening to notification after creation of instance in Openstack

Am interested in finding out if there is a way to create a listener within openstack which gets notified every time a new instance gets created.
Try to take a look at OpenStack workload measuring project https://launchpad.net/ceilometer
One way to do this is by using Django signals. So, you can create a signal and send it after the line of code which creates an instance. The function which expects the notification can be made the receiver which listens to this signal. The function will wait till it receives the signal.As an example:
#Declaring a signal
from django.dispatch import Signal
instance_signal = Signal(providing_args=['param1', 'param2'])
#function that sends the signal
def instance_create():
--code that creates the instance
instance_signal.send(sender='instance_create', param1='I am param 1', param2='I am param 2')
#Defining the function that listens to this signal(the receiver)
def notify_me(**kwargs):
x, y= kwargs['param1'], kwargs['param2']
#Connect the signal to the receiver (Can be written anywhere in the code)
instance_signal.connect(notify_me)
The best part about Django Signals is that you can create the signal, the receiver function and connect them anywhere in the whole application. Django Signals are very useful in scheduling tasks or in your case, receiving notifications.

Resources