Develop a Python program that communicates with a Kafka cluster, produces messages to a topic, consumes messages from the same topic, and processes the consumed messages using a specified algorithm (e.g., word count, sentiment analysis).
To develop a Python program that communicates with a Kafka cluster, you'll need to install the `kafka-python` library. You can do this using pip:

```bash
pip install kafka-python
```

Now let's create a simple producer and consumer for a Kafka topic.

1. Producer: This will produce messages to a Kafka topic.
2. Consumer: This will consume messages from the same Kafka topic.
3. Processing: We'll use a simple word count algorithm to process the consumed messages.

Here's the complete code:

```python
from kafka import KafkaProducer, KafkaConsumer
import json
from collections import defaultdict

# Function to create a Kafka producer
def create_producer():
    return KafkaProducer(bootstrap_servers='localhost:9092',
                         value_serializer=lambda v: json.dumps(v).encode('utf-8'))

# Function to create a Kafka consumer
def create_consumer(topic):
    return KafkaConsumer(topic,
                         bootstrap_servers='localhost:9092',
                         value_deserializer=lambda m: json.loads(m.decode('utf-8')))

# Function to send messages to a Kafka topic
def send_messages(producer, topic, messages):
    for message in messages:
        producer.send(topic, message)
    producer.flush()

# Function to consume messages from a Kafka topic and process them using a word count algorithm
def consume_and_process_messages(consumer):
    word_count = defaultdict(int)
    
    for message in consumer:
        words = message.value.split()
        
        for word in words:
            word_count[word] += 1
        
        print("Updated Word Count:", dict(word_count))

if __name__ == "__main__":
    # Create a Kafka producer
    producer = create_producer()

    # Send messages to the Kafka topic
    topic = 'test-topic'
    messages = ["Hello world", "Kafka is great", "Python is awesome"]
    send_messages(producer, topic, messages)

    # Create a Kafka consumer
    consumer = create_consumer(topic)

    # Consume and process messages from the Kafka topic
    consume_and_process_messages(consumer)
```

Replace `'localhost:9092'` with your Kafka cluster's bootstrap server address. This example assumes you have a running Kafka instance on your local machine.

To run this program, make sure you have a Kafka broker running locally (or update the `bootstrap_servers` parameter to point to your remote Kafka broker). Then simply execute the Python script:

```bash
python kafka_producer_consumer.py
```

The output should show the updated word count for each message consumed from the Kafka topic:

```
Updated Word Count: {'Hello': 1, 'world': 1}
Updated Word Count: {'Hello': 1, 'world': 1, 'Kafka': 1, 'is': 1, 'great': 1}
Updated Word Count: {'Hello': 1, 'world': 1, 'Kafka': 1, 'is': 1, 'great': 1, 'Python': 1, 'awesome': 1}
```

This is a simple example of producing and consuming messages using Kafka in Python. You can modify the processing function to implement more complex algorithms like sentiment analysis or other data processing tasks.