Saturday, January 12, 2019

Consuming from specific Offset, in a Topic, with Confluent Kafka .Net client


From the example in the home page help here https://github.com/confluentinc/confluent-kafka-dotnet#basic-consumer-example 

Change below
c.Subscribe("my-topic");

and update it as below (assuming topic is "my-topic" and offset is 123456)

c.Assign(new TopicPartitionOffset(new TopicPartition("my-topic", new Partition()), new Offset(123456)));


Monday, January 7, 2019

Confluent-kafka-dotnet Consumer (client) - sasl configuration example

To use SSL Auth via SASL for Confluent's .NET Client for Apache Kafka,
update the example in the home page help here https://github.com/confluentinc/confluent-kafka-dotnet#basic-consumer-example with below config


var config = new ConsumerConfig

{
    BootstrapServers = brokerList,
    GroupId = groupId,
    EnableAutoCommit = false,
    StatisticsIntervalMs = 5000,
    SessionTimeoutMs = 6000,
    AutoOffsetReset = AutoOffsetResetType.Earliest,
    SecurityProtocol = SecurityProtocolType.Sasl_Ssl,
    SaslMechanism = SaslMechanismType.ScramSha512,
    SaslUsername = "mykafkausername",
    SaslPassword = "mykafkapassword",
    SslCaLocation = "MyKafkaCA.pem" //PEM file location (you may have to copy this to the .bin location
};


Note: 1.0 beta3 has the below changes
AutoOffsetReset = AutoOffsetReset.Earliest,
SecurityProtocol = SecurityProtocol.SaslSsl,
SaslMechanism = SaslMechanism.ScramSha512,

Windows - check to see if a remote server port is open

We can use portqry tool for this. Windows server editions should already come with this tool.

if not already in windows, you can download a command line or UI version from below
https://support.microsoft.com/en-us/help/310099/description-of-the-portqry-exe-command-line-utility

Usage is as below.
For example, to check if servername has port 80 open, do below

portqry -n servername -e 80

Friday, January 4, 2019

Unity - How to take a screenshot in game with script (at a specific resolution)

Attach below script to any object in your game. Click Play in editor and at the desired point, press "z" in keyboard to take your screenshot as a png file (if game is built, use Ctrl-Z). The screenshot will be stored (ie; the save location) in your Unity project's root folder


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TakeScreenShot : MonoBehaviour {

 // Update is called once per frame
 void Update () {
#if UNITY_EDITOR
        if (Input.GetKey(KeyCode.Z))
#else
     if((Input.GetKey(KeyCode.RightControl) 
      || Input.GetKey(KeyCode.LeftControl)) 
        && Input.GetKeyDown(KeyCode.Z))
#endif
        {
            Debug.Log("Taking screenshot");
            ScreenCapture.CaptureScreenshot("ScreenShot-" + 
             UnityEngine.SceneManagement.SceneManager.GetActiveScene().name + 
             ".png");
            Debug.Log("Done");
        }           
    }
}


Tip: If you want a specific resolution of screenshot, make sure to set this in the player (ie; in Game tab)
In the below example, we are setting resolution to 2400 x 1200. When you use above script, the saved screenshot will have the same resolution.

See example below. Use + symbol to add custom resolutions

Turn on Windows 11 Fast Boot

If windows starting is slow, to enable windows 11 fast startup/boot,  Press Windows + R, type powercfg.cpl, and hit Enter.  This will direct...